diff options
author | Dylan William Hardison <dylan@hardison.net> | 2017-04-26 21:33:11 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2017-04-26 21:33:19 +0200 |
commit | c82963a57cf97932870e11de8cf2a6205132b954 (patch) | |
tree | 74724c840146cb9dd0713a9251f96114df7efc51 /Bugzilla/Template.pm | |
parent | effcc512d52b6bfca05db4df18087bbc2ca8057e (diff) | |
download | bugzilla-c82963a57cf97932870e11de8cf2a6205132b954.tar.gz bugzilla-c82963a57cf97932870e11de8cf2a6205132b954.tar.xz |
Bug 1352264 - Preload all templates
Diffstat (limited to 'Bugzilla/Template.pm')
-rw-r--r-- | Bugzilla/Template.pm | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index 65396b96d..cb10544f1 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -12,6 +12,7 @@ use 5.10.1; use strict; use warnings; +use Bugzilla::Template::PreloadProvider; use Bugzilla::Bug; use Bugzilla::Constants; use Bugzilla::Hook; @@ -47,6 +48,8 @@ use constant FORMAT_3_SIZE => [19,28,28]; use constant FORMAT_DOUBLE => '%19s %-55s'; use constant FORMAT_2_SIZE => [19,55]; +my %SHARED_PROVIDERS; + # Pseudo-constant. sub SAFE_URL_REGEXP { my $safe_protocols = join('|', SAFE_PROTOCOLS); @@ -973,10 +976,12 @@ sub create { PLUGIN_BASE => 'Bugzilla::Template::Plugin', - CONSTANTS => _load_constants(), - # Default variables for all templates VARIABLES => { + # Some of these are not really constants, and doing this messes up preloading. + # they are now fake constants. + constants => _load_constants(), + # Function for retrieving global parameters. 'Param' => sub { return Bugzilla->params->{$_[0]}; }, @@ -1115,12 +1120,18 @@ sub create { 'is_mobile_browser' => sub { return Bugzilla->cgi->user_agent =~ /Mobi/ }, }, }; + + # under mod_perl, use a provider (template loader) that preloads all templates into memory + my $provider_class + = $ENV{MOD_PERL} + ? 'Bugzilla::Template::PreloadProvider' + : 'Template::Provider'; + # Use a per-process provider to cache compiled templates in memory across # requests. my $provider_key = join(':', @{ $config->{INCLUDE_PATH} }); - my $shared_providers = Bugzilla->process_cache->{shared_providers} ||= {}; - $shared_providers->{$provider_key} ||= Template::Provider->new($config); - $config->{LOAD_TEMPLATES} = [ $shared_providers->{$provider_key} ]; + $SHARED_PROVIDERS{$provider_key} ||= $provider_class->new($config); + $config->{LOAD_TEMPLATES} = [ $SHARED_PROVIDERS{$provider_key} ]; # BMO - use metrics subclass local $Template::Config::CONTEXT = Bugzilla->metrics_enabled() @@ -1209,7 +1220,7 @@ sub precompile_templates { delete Bugzilla->request_cache->{template}; # Clear out the cached Provider object - Bugzilla->process_cache->{shared_providers} = undef; + %SHARED_PROVIDERS = (); print install_string('done') . "\n" if $output; } |