[Bps-public-commit] r15644 - in RT-Extension-MergeUsers: lib/RT

ruz at bestpractical.com ruz at bestpractical.com
Fri Aug 29 13:51:03 EDT 2008


Author: ruz
Date: Fri Aug 29 13:51:02 2008
New Revision: 15644

Modified:
   RT-Extension-MergeUsers/Makefile.PL
   RT-Extension-MergeUsers/lib/RT/User_Vendor.pm

Log:
* add cache for negative results as SB doesn't do that for us

Modified: RT-Extension-MergeUsers/Makefile.PL
==============================================================================
--- RT-Extension-MergeUsers/Makefile.PL	(original)
+++ RT-Extension-MergeUsers/Makefile.PL	Fri Aug 29 13:51:02 2008
@@ -8,4 +8,6 @@
 version_from    ('lib/RT/Extension/MergeUsers.pm');
 license         ('GPL version 2');
 
-&WriteAll;
+requires        ('Hook::LexWrap');
+
+WriteAll();

Modified: RT-Extension-MergeUsers/lib/RT/User_Vendor.pm
==============================================================================
--- RT-Extension-MergeUsers/lib/RT/User_Vendor.pm	(original)
+++ RT-Extension-MergeUsers/lib/RT/User_Vendor.pm	Fri Aug 29 13:51:02 2008
@@ -44,10 +44,22 @@
 # 
 # END BPS TAGGED BLOCK }}}
 
-no warnings qw(redefine);
+use strict;
+use warnings; no warnings qw(redefine);
 
 package RT::User;
 
+our %EFFECTIVE_ID_CACHE;
+
+use RT::Interface::Web::Handler;
+use Hook::LexWrap;
+
+{ my $i = 0;
+wrap 'RT::Interface::Web::Handler::CleanupRequest' => sub {
+    return if ++$i%100; # flush cache every N requests
+    %EFFECTIVE_ID_CACHE = ();
+}; }
+
 sub CanonicalizeEmailAddress {
     my $self = shift;
     my $address = shift;
@@ -77,17 +89,26 @@
 sub LoadByCols {
     my $self = shift;
     $self->SUPER::LoadByCols(@_);
-    return $self->id unless $self->id;
+    return $self->id unless my $oid = $self->id;
 
-    my $effective_id = RT::Attribute->new( $RT::SystemUser );
-    $effective_id->LoadByCols(
-        Name => 'EffectiveId',
-        ObjectType => ref($self) || $self,
-        ObjectId => $self->id
-    );
-    if ( $effective_id->id && $effective_id->Content && $effective_id->Content != $self->id ) {
-        $self->LoadByCols( id => $effective_id->Content );
+    unless ( exists $EFFECTIVE_ID_CACHE{ $oid } ) {
+        my $effective_id = RT::Attribute->new( $RT::SystemUser );
+        $effective_id->LoadByCols(
+            Name       => 'EffectiveId',
+            ObjectType => ref($self) || $self,
+            ObjectId   => $oid,
+        );
+        if ( $effective_id->id && $effective_id->Content && $effective_id->Content != $oid ) {
+            $self->LoadByCols( id => $effective_id->Content );
+            $EFFECTIVE_ID_CACHE{ $oid } = $self->id;
+        } else {
+            $EFFECTIVE_ID_CACHE{ $oid } = undef;
+        }
+    }
+    elsif ( defined $EFFECTIVE_ID_CACHE{ $oid } ) {
+        $self->LoadByCols( id => $EFFECTIVE_ID_CACHE{ $oid } );
     }
+
     return $self->id;
 }
 



More information about the Bps-public-commit mailing list