[Rt-commit] rt branch, 4.2/hash-instead-of-module-for-acl-cache, created. rt-4.0.6-489-gd56f4ac
Ruslan Zakirov
ruz at bestpractical.com
Sun Aug 26 17:03:04 EDT 2012
The branch, 4.2/hash-instead-of-module-for-acl-cache has been created
at d56f4acbf47618595666637d41b0c79e73f43e5f (commit)
- Log -----------------------------------------------------------------
commit d56f4acbf47618595666637d41b0c79e73f43e5f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Mon Aug 27 00:56:54 2012 +0400
use hash for ACL_CACHE instead of TimedExpiry
If we don't flush the cache when situation changes
then it will result in bugs. 60 seconds expiration
time is just too big.
for web interface we flush cache on every request
for single process command line tool flushing in
right places should cover everything
diff --git a/lib/RT/Principal.pm b/lib/RT/Principal.pm
index 4c225c4..7d80cf9 100644
--- a/lib/RT/Principal.pm
+++ b/lib/RT/Principal.pm
@@ -60,9 +60,6 @@ sub Table {'Principals'}
-use Cache::Simple::TimedExpiry;
-
-
use RT;
use RT::Group;
use RT::User;
@@ -292,9 +289,9 @@ sub HasRight {
}
{
- my $cached = $_ACL_CACHE->fetch(
+ my $cached = $_ACL_CACHE->{
$self->id .';:;'. ref($args{'Object'}) .'-'. $args{'Object'}->id
- );
+ };
return $cached->{'SuperUser'} || $cached->{ $args{'Right'} }
if $cached;
}
@@ -318,19 +315,19 @@ sub HasRight {
$full_hashkey .= ";:;".$ref_id;
my $short_hashkey = join(";:;", $self->id, $args{'Right'}, $ref_id);
- my $cached_answer = $_ACL_CACHE->fetch($short_hashkey);
+ my $cached_answer = $_ACL_CACHE->{ $short_hashkey };
return $cached_answer > 0 if defined $cached_answer;
}
{
- my $cached_answer = $_ACL_CACHE->fetch($full_hashkey);
+ my $cached_answer = $_ACL_CACHE->{ $full_hashkey };
return $cached_answer > 0 if defined $cached_answer;
}
my ( $hitcount, $via_obj ) = $self->_HasRight(%args);
- $_ACL_CACHE->set( $full_hashkey => $hitcount ? 1 : -1 );
- $_ACL_CACHE->set( join(';:;', $self->id, $args{'Right'},$via_obj) => 1 )
+ $_ACL_CACHE->{ $full_hashkey } = $hitcount ? 1 : -1;
+ $_ACL_CACHE->{ join ';:;', $self->id, $args{'Right'}, $via_obj } = 1
if $via_obj && $hitcount;
return ($hitcount);
@@ -371,7 +368,7 @@ sub HasRights {
}
my $cache_key = $self->id .';:;'. ref($object) .'-'. $object->id;
- my $cached = $_ACL_CACHE->fetch($cache_key);
+ my $cached = $_ACL_CACHE->{ $cache_key };
return $cached if $cached;
push @{ $args{'EquivObjects'} }, $object;
@@ -427,7 +424,7 @@ sub HasRights {
delete $res{'ExecuteCode'} if
RT->Config->Get('DisallowExecuteCode');
- $_ACL_CACHE->store( $cache_key, \%res );
+ $_ACL_CACHE->{ $cache_key } = \%res;
return \%res;
}
@@ -682,10 +679,7 @@ Cleans out and reinitializes the user rights cache
=cut
sub InvalidateACLCache {
- $_ACL_CACHE = Cache::Simple::TimedExpiry->new();
- my $lifetime;
- $lifetime = $RT::Config->Get('ACLCacheLifetime') if $RT::Config;
- $_ACL_CACHE->expire_after( $lifetime || 60 );
+ $_ACL_CACHE = {}
}
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index b801c28..ba7b860 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -2990,7 +2990,7 @@ sub Next {
# if we found a ticket with this option enabled then
# all tickets we found are ACLed, cache this fact
my $key = join ";:;", $self->CurrentUser->id, 'ShowTicket', 'RT::Ticket-'. $Ticket->id;
- $RT::Principal::_ACL_CACHE->set( $key => 1 );
+ $RT::Principal::_ACL_CACHE->{ $key } = 1;
return $Ticket;
}
elsif ( $Ticket->CurrentUserHasRight('ShowTicket') ) {
@@ -3020,7 +3020,7 @@ sub _RolesCanSee {
my $cache_key = 'RolesHasRight;:;ShowTicket';
- if ( my $cached = $RT::Principal::_ACL_CACHE->fetch( $cache_key ) ) {
+ if ( my $cached = $RT::Principal::_ACL_CACHE->{ $cache_key } ) {
return %$cached;
}
@@ -3050,7 +3050,7 @@ sub _RolesCanSee {
$RT::Logger->error('ShowTicket right is granted on unsupported object');
}
}
- $RT::Principal::_ACL_CACHE->set( $cache_key => \%res );
+ $RT::Principal::_ACL_CACHE->{ $cache_key } = \%res;
return %res;
}
@@ -3059,7 +3059,7 @@ sub _DirectlyCanSeeIn {
my $id = $self->CurrentUser->id;
my $cache_key = 'User-'. $id .';:;ShowTicket;:;DirectlyCanSeeIn';
- if ( my $cached = $RT::Principal::_ACL_CACHE->fetch( $cache_key ) ) {
+ if ( my $cached = $RT::Principal::_ACL_CACHE->{ $cache_key } ) {
return @$cached;
}
@@ -3087,7 +3087,7 @@ sub _DirectlyCanSeeIn {
if ( $type eq 'RT::System' ) {
# If user is direct member of a group that has the right
# on the system then he can see any ticket
- $RT::Principal::_ACL_CACHE->set( $cache_key => [-1] );
+ $RT::Principal::_ACL_CACHE->{ $cache_key } = [-1];
return (-1);
}
elsif ( $type eq 'RT::Queue' ) {
@@ -3097,7 +3097,7 @@ sub _DirectlyCanSeeIn {
$RT::Logger->error('ShowTicket right is granted on unsupported object');
}
}
- $RT::Principal::_ACL_CACHE->set( $cache_key => \@res );
+ $RT::Principal::_ACL_CACHE->{ $cache_key } = \@res;
return @res;
}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list