summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Template.pm
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2017-05-27 01:48:49 +0200
committerDylan William Hardison <dylan@hardison.net>2017-05-27 01:48:49 +0200
commit48cf53e5b1891a29645432121467e29cdb9e061a (patch)
tree0d9ea38f4c8e5a07982018a216316fea6c3ac27b /Bugzilla/Template.pm
parentb1aece569468612c9a69332fc7a530749b39e977 (diff)
downloadbugzilla-48cf53e5b1891a29645432121467e29cdb9e061a.tar.gz
bugzilla-48cf53e5b1891a29645432121467e29cdb9e061a.tar.xz
Bug 1352264 - Preload all templates (re-apply)
Diffstat (limited to 'Bugzilla/Template.pm')
-rw-r--r--Bugzilla/Template.pm23
1 files changed, 17 insertions, 6 deletions
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm
index 29b1d4a13..87ab2929e 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);
@@ -968,10 +971,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]}; },
@@ -1110,12 +1115,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()
@@ -1204,7 +1215,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;
}