Commit b6efaa8e authored by Alex Vandiver's avatar Alex Vandiver
Browse files

Remove caching of template objects in rt-crontool

rt-crontool 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 caused Template objects which already had a
MIMEObj to retain them.  In the context of rt-crontool, this causes the
same content (that formed from the first matching 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.
parent ae47fb45
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment