Item10601: Purging of templates causes failure of ICON macros
Priority: Urgent
Current State: Closed
Released In: n/a
Target Release: n/a
Publisher::publishUsingTemplate
purges the templates after each topic is rendered:
565 if ($Foswiki::Plugins::SESSION->can('templates') and
566 $Foswiki::Plugins::SESSION->{templates} and
567 ref $Foswiki::Plugins::SESSION->{templates} and
568 $Foswiki::Plugins::SESSION->{templates}->can('finish') )
569 {
570 $Foswiki::Plugins::SESSION->{templates}->finish();
571 undef $Foswiki::Plugins::SESSION->{templates};
572 }
The comments preceding the code indicate this is to fix server load issues in generating the
PublishPlugin
summary output if there are lots of errors during the
Publish
process.
Unfortunately, this interacts poorly with an optimization in
Foswiki/Macros/ICON.pm
in the
ICON
subroutine which tries not to continually reload the icon templates:
155 if ( !defined( $this->{_ICONSTEMPLATE} ) ) {
156
157 #if we fail to load once, don't try again.
158 $this->{_ICONSTEMPLATE} = $this->templates->readTemplate('icons');
159 }
The problem is that when
publishUsingTemplate
purges the templates, when the
ICON
subroutine is next invoked it doesn't know it needs to reload the icon templates, assumes they're there, and fails.
(BTW, the comment in the
ICON
optimization code doesn't seem to match the current code base. If
Templates::readTemplate
fails it will throw an oops and you'll never traverse this code path again. Instead, this code ensures that if the template is
successfully loaded it will never get loaded again.)
The following kludge fixes the problem by explicitly destroying the
_ICONSTEMPLATE
semaphore when purging the templates.
565 if ($Foswiki::Plugins::SESSION->can('templates') and
566 $Foswiki::Plugins::SESSION->{templates} and
567 ref $Foswiki::Plugins::SESSION->{templates} and
568 $Foswiki::Plugins::SESSION->{templates}->can('finish') )
569 {
570 $Foswiki::Plugins::SESSION->{templates}->finish();
571 undef $Foswiki::Plugins::SESSION->{templates};
572 delete $Foswiki::Plugins::SESSION->{_ICONSTEMPLATE};
573 }
--
DiabJerius - 05 Apr 2011
This problem is also seen with the
ImagePlugin, which also caches template information. On my site it seems the safest approach is to simply comment out the code which purges the templates.
--
DiabJerius - 05 Apr 2011
I agree. I have set a configuration var with this as the default state (no purge).
Foswiki:Main.MichaelTempest can enable it if he still needs it.
--
CrawfordCurrie - 25 May 2011