[Rt-commit] [svn] r1866 - in rt/branches/PLATANO-EXPERIMENTAL-CSS: . lib/RT sbin

jesse at pallas.eruditorum.org jesse at pallas.eruditorum.org
Thu Nov 11 03:52:05 EST 2004


Author: jesse
Date: Thu Nov 11 03:52:05 2004
New Revision: 1866

Modified:
   rt/branches/PLATANO-EXPERIMENTAL-CSS/   (props changed)
   rt/branches/PLATANO-EXPERIMENTAL-CSS/lib/RT/Principal_Overlay.pm
   rt/branches/PLATANO-EXPERIMENTAL-CSS/sbin/rt-test-dependencies.in
Log:
 r9128 at tinbook:  jesse | 2004-11-11T04:07:58.364185Z
  r8959 at tinbook:  jesse | 2004-11-09T05:47:13.371897Z
  Switched to using Cache::Simple::TimedExpiry for our ACL cache, rather 
  than our overly convoluted (and slower) ACL cache code in Prinicpal_Overlay.pm
  
  SearchBuilder already depends on C::S::TE, so this isn't a new dep
  
 


Modified: rt/branches/PLATANO-EXPERIMENTAL-CSS/lib/RT/Principal_Overlay.pm
==============================================================================
--- rt/branches/PLATANO-EXPERIMENTAL-CSS/lib/RT/Principal_Overlay.pm	(original)
+++ rt/branches/PLATANO-EXPERIMENTAL-CSS/lib/RT/Principal_Overlay.pm	Thu Nov 11 03:52:05 2004
@@ -48,11 +48,18 @@
 use warnings;
 
 no warnings qw(redefine);
-use vars qw(%_ACL_KEY_CACHE);
+
+use Cache::Simple::TimedExpiry;
+
+
 
 use RT::Group;
 use RT::User;
 
+# Set up the ACL cache on startup
+our $_ACL_CACHE;
+_InvalidateACLCache();
+
 # {{{ IsGroup
 
 =head2 IsGroup
@@ -298,60 +305,20 @@
     };
     # }}}
 
-    #Anything older than 60 seconds needs to be rechecked
-    my $cache_timeout = ( time - 60 );
 
     # {{{ if we've cached a positive result for this query, return 1
-    if (    ( defined $self->_ACLCache->{"$hashkey"} )
-         && ( $self->_ACLCache->{"$hashkey"}{'val'} == 1 )
-         && ( defined $self->_ACLCache->{"$hashkey"}{'set'} )
-         && ( $self->_ACLCache->{"$hashkey"}{'set'} > $cache_timeout ) ) {
-
-        #$RT::Logger->debug("Cached ACL win for ".  $args{'Right'}.$args{'Scope'}.  $args{'AppliesTo'}."\n");	    
-        return ( 1);
-    }
-    # }}}
-
-    #  {{{ if we've cached a negative result for this query return undef
-    elsif (    ( defined $self->_ACLCache->{"$hashkey"} )
-            && ( $self->_ACLCache->{"$hashkey"}{'val'} == -1 )
-            && ( defined $self->_ACLCache->{"$hashkey"}{'set'} )
-            && ( $self->_ACLCache->{"$hashkey"}{'set'} > $cache_timeout ) ) {
-
-        #$RT::Logger->debug("Cached ACL loss decision for ".  $args{'Right'}.$args{'Scope'}.  $args{'AppliesTo'}."\n");	    
-
-        return (undef);
-    }
-    # }}}
-
-    # }}}
-
-
-
-    #  {{{ Out of date docs
-    
-    #   We want to grant the right if:
 
+        my $cached_answer = $_ACL_CACHE->fetch($hashkey);
+        # Returns undef on cache miss
+        if (defined $cached_answer) {
+            if ($cached_answer == 1) {
+                   return(1);
+                }
+            elsif ($cached_answer == -1) {
+                return(0); 
+             }
+        }
 
-    #    # The user has the right as a member of a system-internal or 
-    #    # user-defined group
-    #
-    #    Find all records from the ACL where they're granted to a group 
-    #    of type "UserDefined" or "System"
-    #    for the object "System or the object "Queue N" and the group we're looking
-    #    at has the recursive member $self->Id
-    #
-    #    # The user has the right based on a role
-    #
-    #    Find all the records from ACL where they're granted to the role "foo"
-    #    for the object "System" or the object "Queue N" and the group we're looking
-    #   at is of domain  ("RT::Queue-Role" and applies to the right queue)
-    #                             or ("RT::Ticket-Role" and applies to the right ticket)
-    #    and the type is the same as the type of the ACL and the group has
-    #    the recursive member $self->Id
-    #
-
-    # }}}
 
     my ( $or_look_at_object_rights, $or_check_roles );
     my $right = $args{'Right'};
@@ -443,35 +410,19 @@
     
     # {{{ if there's a match, the right is granted 
     if ($hitcount) {
-
-        # Cache a positive hit.
-        $self->_ACLCache->{"$hashkey"}{'set'} = time;
-        $self->_ACLCache->{"$hashkey"}{'val'} = 1;
+        $_ACL_CACHE->set($hashkey => 1);
         return (1);
     }
-    # }}}
-    # {{{ If there's no match on groups, try it on roles
-    else {   
-
+    # Now check the roles query
     	$hitcount = $self->_Handle->FetchResult($roles_query);
 
-        if ($hitcount) {
-
-            # Cache a positive hit.
-            $self->_ACLCache->{"$hashkey"}{'set'} = time;
-            $self->_ACLCache->{"$hashkey"}{'val'} = 1;
-            return (1);
-	    }
-
-        else {
-            # cache a negative hit
-            $self->_ACLCache->{"$hashkey"}{'set'} = time;
-            $self->_ACLCache->{"$hashkey"}{'val'} = -1;
-
-            return (undef);
-	    }
+    if ($hitcount) {
+        $_ACL_CACHE->set($hashkey => 1);
+        return (1);
     }
-    # }}}
+    # We failed to find an acl hit
+     $_ACL_CACHE->set($hashkey => -1);
+     return (undef);
 }
 
 # }}}
@@ -513,23 +464,6 @@
 
 # {{{ ACL caching
 
-# {{{ _ACLCache
-
-=head2 _ACLCache
-
-# Function: _ACLCache
-# Type    : private instance
-# Args    : none
-# Lvalue  : hash: ACLCache
-# Desc    : Returns a reference to the Key cache hash
-
-=cut
-
-sub _ACLCache {
-    return(\%_ACL_KEY_CACHE);
-}
-
-# }}}
 
 # {{{ _InvalidateACLCache
 
@@ -540,7 +474,9 @@
 =cut
 
 sub _InvalidateACLCache {
-    %_ACL_KEY_CACHE = ();
+    $_ACL_CACHE = Cache::Simple::TimedExpiry->new();
+    $_ACL_CACHE->expire_after($RT::ACLCacheLifetime||60);
+
 }
 
 # }}}

Modified: rt/branches/PLATANO-EXPERIMENTAL-CSS/sbin/rt-test-dependencies.in
==============================================================================
--- rt/branches/PLATANO-EXPERIMENTAL-CSS/sbin/rt-test-dependencies.in	(original)
+++ rt/branches/PLATANO-EXPERIMENTAL-CSS/sbin/rt-test-dependencies.in	Thu Nov 11 03:52:05 2004
@@ -143,6 +143,7 @@
 Tree::Simple 1.04
 Scalar::Util
 Module::Versions::Report
+Cache::Simple::TimedExpiry
 YAML
 .
 


More information about the Rt-commit mailing list