[Rt-commit] rt branch, 4.2/hash-instead-of-module-for-acl-cache, created. rt-4.1.6-344-g6d8078f
Ruslan Zakirov
ruz at bestpractical.com
Tue Mar 12 17:48:24 EDT 2013
The branch, 4.2/hash-instead-of-module-for-acl-cache has been created
at 6d8078fa78651c60c3e30ea5946e0862865e0917 (commit)
- Log -----------------------------------------------------------------
commit 6d8078fa78651c60c3e30ea5946e0862865e0917
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 fbb88d9..05a8348 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;
@@ -308,9 +305,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;
}
@@ -331,19 +328,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);
@@ -384,7 +381,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;
@@ -438,7 +435,7 @@ sub HasRights {
delete $res{'ExecuteCode'} if
RT->Config->Get('DisallowExecuteCode');
- $_ACL_CACHE->store( $cache_key, \%res );
+ $_ACL_CACHE->{ $cache_key } = \%res;
return \%res;
}
@@ -690,10 +687,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 6c81505..efd3b50 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -2777,7 +2777,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') ) {
@@ -2807,7 +2807,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;
}
@@ -2837,7 +2837,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;
}
@@ -2846,7 +2846,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;
}
@@ -2874,7 +2874,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' ) {
@@ -2884,7 +2884,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