diff options
author | Max Kanat-Alexander <mkanat@bugzilla.org> | 2010-03-14 01:32:32 +0100 |
---|---|---|
committer | Max Kanat-Alexander <mkanat@bugzilla.org> | 2010-03-14 01:32:32 +0100 |
commit | 217beee45f5ba22aea80c8a61a639b55fe53293c (patch) | |
tree | e7865b6ac2b112cb6f5e22f6cb5d4e7aa77fe3f8 /Bugzilla/Util.pm | |
parent | f276a11f82d1670eea4014f4d87b289d4b7921ca (diff) | |
download | bugzilla-217beee45f5ba22aea80c8a61a639b55fe53293c.tar.gz bugzilla-217beee45f5ba22aea80c8a61a639b55fe53293c.tar.xz |
Bug 498309: Speed up show_bug.cgi when there are many comments by caching
field-descs globally for all template calls
r=LpSolit, a=LpSolit
Diffstat (limited to 'Bugzilla/Util.pm')
-rw-r--r-- | Bugzilla/Util.pm | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index 437979c85..35a5c0aea 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -44,7 +44,7 @@ use base qw(Exporter); file_mod_time is_7bit_clean bz_crypt generate_random_password validate_email_syntax clean_text - get_text disable_utf8); + get_text template_var disable_utf8); use Bugzilla::Constants; @@ -621,6 +621,26 @@ sub get_text { return $message; } +sub template_var { + my $name = shift; + my $cache = Bugzilla->request_cache->{util_template_var} ||= {}; + my $template = Bugzilla->template_inner; + my $lang = $template->context->{bz_language}; + return $cache->{$lang}->{$name} if defined $cache->{$lang}; + my %vars; + # Note: If we suddenly start needing a lot of template_var variables, + # they should move into their own template, not field-descs. + my $result = $template->process('global/field-descs.none.tmpl', + { vars => \%vars, in_template_var => 1 }); + # Bugzilla::Error can't be "use"d in Bugzilla::Util. + if (!$result) { + require Bugzilla::Error; + Bugzilla::Error::ThrowTemplateError($template->error); + } + $cache->{$lang} = \%vars; + return $vars{$name}; +} + sub disable_utf8 { if (Bugzilla->params->{'utf8'}) { binmode STDOUT, ':bytes'; # Turn off UTF8 encoding. @@ -902,6 +922,14 @@ A string. =back + +=item C<template_var> + +This is a method of getting the value of a variable from a template in +Perl code. The available variables are in the C<global/field-descs.none.tmpl> +template. Just pass in the name of the variable that you want the value of. + + =back =head2 Formatting Time |