[Rt-commit] rt branch, 4.2/attributes-global-cache, created. rt-4.2.12-110-gf0f84d3

Dustin Graves dustin at bestpractical.com
Mon Mar 7 20:36:42 EST 2016


The branch, 4.2/attributes-global-cache has been created
        at  f0f84d3e5a1ff74fac1f9979f58b3028571e5bc9 (commit)

- Log -----------------------------------------------------------------
commit f0f84d3e5a1ff74fac1f9979f58b3028571e5bc9
Author: Dustin Graves <dustin at bestpractical.com>
Date:   Tue Mar 8 01:16:44 2016 +0000

    change attributes cache on RT::Record to global and flush on every request

diff --git a/lib/RT/Interface/Web/Handler.pm b/lib/RT/Interface/Web/Handler.pm
index ad1068b..d4ccfed 100644
--- a/lib/RT/Interface/Web/Handler.pm
+++ b/lib/RT/Interface/Web/Handler.pm
@@ -199,6 +199,8 @@ sub CleanupRequest {
     File::Temp::cleanup()
             unless $INC{'Test/WWW/Mechanize/PSGI.pm'};
 
+    # flush attributes cache
+    %RT::Record::GLOBAL_ATTR_CACHE = ();
 
 }
 
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 757ff41..996ae71 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -80,6 +80,7 @@ use RT::Shredder::Constants;
 use RT::Shredder::Exceptions;
 
 our $_TABLE_ATTR = { };
+our %GLOBAL_ATTR_CACHE;
 
 
 sub _Init {
@@ -175,12 +176,13 @@ Return this object's attributes as an RT::Attributes object
 
 sub Attributes {
     my $self = shift;
-    unless ($self->{'attributes'}) {
-        $self->{'attributes'} = RT::Attributes->new($self->CurrentUser);
-        $self->{'attributes'}->LimitToObject($self);
-        $self->{'attributes'}->OrderByCols({FIELD => 'id'});
+    my $cache_key = ref($self)."-".$self->id;
+    unless ($GLOBAL_ATTR_CACHE{$cache_key}->{'attributes'}) {
+        $GLOBAL_ATTR_CACHE{$cache_key}->{'attributes'} = RT::Attributes->new($self->CurrentUser);
+        $GLOBAL_ATTR_CACHE{$cache_key}->{'attributes'}->LimitToObject($self);
+        $GLOBAL_ATTR_CACHE{$cache_key}->{'attributes'}->OrderByCols({FIELD => 'id'});
     }
-    return ($self->{'attributes'});
+    return ($GLOBAL_ATTR_CACHE{$cache_key}->{'attributes'});
 }
 
 
@@ -270,7 +272,7 @@ sub FirstAttribute {
 
 sub ClearAttributes {
     my $self = shift;
-    delete $self->{'attributes'};
+    delete $GLOBAL_ATTR_CACHE{ref($self)."-".$self->id}->{'attributes'} if $self->id;
 
 }
 

-----------------------------------------------------------------------


More information about the rt-commit mailing list