[Rt-commit] rt branch, 4.2/cron-template-caching, created. rt-4.2.4rc1-1-g293f24e

Alex Vandiver alexmv at bestpractical.com
Tue May 6 18:26:27 EDT 2014


The branch, 4.2/cron-template-caching has been created
        at  293f24e178a00602d282a3d6f88e7a53ec0592b2 (commit)

- Log -----------------------------------------------------------------
commit 293f24e178a00602d282a3d6f88e7a53ec0592b2
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue May 6 18:17:42 2014 -0400

    Remove caching of template objects in rt-cronjob
    
    rt-cronjob has cached lookup of the the name of the template ever since
    3.8, when the ability to specify a template by name was introduced.  The
    template object is modified in memory when ->Parse is called, however,
    updating its ->MIMEObj.  This was not a problem because
    RT::Action::SendEmail->Prepare calls ->Parse, which clears out its
    ->MIMEObj.
    
    Unfortunately, a1a4f73e Template objects which already had a MIMEObj to
    retain them.  In the context of rt-cronjob, this causes the same content
    (that formed from the first mathcing ticket) to be sent out on all
    tickets whenever RT::Action::SendEmail is used as the target action.
    RT::Action::RecordCorrespondence is unaffected, however, as it always
    calls ->Parse.
    
    Remove the unnecessary cache in rt-conjob; looking up a Template objects
    per RT::Ticket result is unlikely to result in performance implications,
    as it is a small and well-indexed table, and caching repeatedly proves
    to be complicated to implement without unexpected side-effects.
    
    Fixes I#29454.

diff --git a/bin/rt-crontool.in b/bin/rt-crontool.in
index 18f2790..45c5163 100644
--- a/bin/rt-crontool.in
+++ b/bin/rt-crontool.in
@@ -253,24 +253,20 @@ sub get_transactions {
 # 
 # =cut
 
-{ my $cache = undef;
 sub get_template {
     my $ticket = shift;
     return undef unless $template;
 
     unless ( $template =~ /\D/ ) {
         # by id
-        return $cache if $cache;
-
-        my $cache = RT::Template->new( RT->SystemUser );
-        $cache->Load( $template );
+        my $template = RT::Template->new( RT->SystemUser );
+        $template->Load( $template );
         die "Failed to load template '$template'"
-            unless $cache->id;
-        return $cache;
+            unless $template->id;
+        return $template;
     }
 
     my $queue = $ticket->Queue;
-    return $cache->{ $queue } if $cache->{ $queue };
 
     my $res = RT::Template->new( RT->SystemUser );
     $res->LoadQueueTemplate( Queue => $queue, Name => $template );
@@ -279,8 +275,8 @@ sub get_template {
         die "Failed to load template '$template', either for queue #$queue or global"
             unless $res->id;
     }
-    return $cache->{ $queue } = $res;
-} }
+    return $res;
+}
 
 
 # =head2 load_module

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


More information about the rt-commit mailing list