summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Lawrence <dlawrence@mozilla.com>2012-10-12 00:41:57 +0200
committerDave Lawrence <dlawrence@mozilla.com>2012-10-12 00:41:57 +0200
commit3b4065719921c2dc6f620aa5aa17d33c7d6d1c95 (patch)
tree234fe8a7e9aee10efdc41b1cbc0ae05afc610608
parentf9decb719a83f4cc15ef483f032c7cd1c37bce10 (diff)
downloadbugzilla-3b4065719921c2dc6f620aa5aa17d33c7d6d1c95.tar.gz
bugzilla-3b4065719921c2dc6f620aa5aa17d33c7d6d1c95.tar.xz
Bug 799257 - Backport bug 795650 and bug 797833 to bmo/4.0 and bmo/4.2 for performance improvement
r=glob
-rw-r--r--Bugzilla.pm13
-rw-r--r--Bugzilla/Template.pm9
-rw-r--r--Bugzilla/Util.pm19
3 files changed, 30 insertions, 11 deletions
diff --git a/Bugzilla.pm b/Bugzilla.pm
index b56f42ec4..b61062a9f 100644
--- a/Bugzilla.pm
+++ b/Bugzilla.pm
@@ -289,9 +289,7 @@ sub input_params {
}
sub localconfig {
- my $class = shift;
- $class->request_cache->{localconfig} ||= read_localconfig();
- return $class->request_cache->{localconfig};
+ return $_[0]->process_cache->{localconfig} ||= read_localconfig();
}
sub params {
@@ -652,6 +650,15 @@ sub request_cache {
return $_request_cache;
}
+# This is a per-process cache. Under mod_cgi it's identical to the
+# request_cache. When using mod_perl, items in this cache live until the
+# worker process is terminated.
+our $_process_cache = {};
+
+sub process_cache {
+ return $_process_cache;
+}
+
# Private methods
# Per-process cleanup. Note that this is a plain subroutine, not a method,
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm
index 245d881d3..b35a9d269 100644
--- a/Bugzilla/Template.pm
+++ b/Bugzilla/Template.pm
@@ -997,6 +997,12 @@ sub create {
'default_authorizer' => new Bugzilla::Auth(),
},
};
+ # 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} ];
local $Template::Config::CONTEXT = 'Bugzilla::Template::Context';
@@ -1078,6 +1084,9 @@ sub precompile_templates {
# If anything created a Template object before now, clear it out.
delete Bugzilla->request_cache->{template};
+ # Clear out the cached Provider object
+ Bugzilla->process_cache->{shared_providers} = undef;
+
print install_string('done') . "\n" if $output;
}
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm
index c2dbdc97d..c754f4081 100644
--- a/Bugzilla/Util.pm
+++ b/Bugzilla/Util.pm
@@ -119,6 +119,9 @@ sub html_quote {
sub html_light_quote {
my ($text) = @_;
+ # admin/table.html.tmpl calls |FILTER html_light| many times.
+ # There is no need to recreate the HTML::Scrubber object again and again.
+ my $scrubber = Bugzilla->process_cache->{html_scrubber};
# List of allowed HTML elements having no attributes.
my @allow = qw(b strong em i u p br abbr acronym ins del cite code var
@@ -140,7 +143,7 @@ sub html_light_quote {
$text =~ s#$chr($safe)$chr#<$1>#go;
return $text;
}
- else {
+ elsif (!$scrubber) {
# We can be less restrictive. We can accept elements with attributes.
push(@allow, qw(a blockquote q span));
@@ -183,14 +186,14 @@ sub html_light_quote {
},
);
- my $scrubber = HTML::Scrubber->new(default => \@default,
- allow => \@allow,
- rules => \@rules,
- comment => 0,
- process => 0);
-
- return $scrubber->scrub($text);
+ Bugzilla->process_cache->{html_scrubber} = $scrubber =
+ HTML::Scrubber->new(default => \@default,
+ allow => \@allow,
+ rules => \@rules,
+ comment => 0,
+ process => 0);
}
+ return $scrubber->scrub($text);
}
sub email_filter {