]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 498309: Speed up show_bug.cgi when there are many comments by caching
authorMax Kanat-Alexander <mkanat@bugzilla.org>
Sun, 14 Mar 2010 00:34:43 +0000 (16:34 -0800)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Sun, 14 Mar 2010 00:34:43 +0000 (16:34 -0800)
field-descs globally for all template calls
r=LpSolit, a=LpSolit

Bugzilla/Template.pm
Bugzilla/Util.pm
template/en/default/global/field-descs.none.tmpl

index 6c6351dad2651332f82c73b199f586fbc70de53e..68ab2a8b374bca8e7add280c0d005b2079999728 100644 (file)
@@ -237,7 +237,7 @@ sub quoteUrls {
     # we have to do this in one pattern, and so this is semi-messy.
     # Also, we can't use $bug_re?$comment_re? because that will match the
     # empty string
-    my $bug_word = get_text('term', { term => 'bug' });
+    my $bug_word = template_var('terms')->{bug};
     my $bug_re = qr/\Q$bug_word\E\s*\#?\s*(\d+)/i;
     my $comment_re = qr/comment\s*\#?\s*(\d+)/i;
     $text =~ s~\b($bug_re(?:\s*,?\s*$comment_re)?|$comment_re)
@@ -763,6 +763,11 @@ sub create {
 
             'feature_enabled' => sub { return Bugzilla->feature(@_); },
 
+            # field_descs can be somewhat slow to generate, so we generate
+            # it only once per-language no matter how many times
+            # $template->process() is called.
+            'field_descs' => sub { return template_var('field_descs') },
+
             'install_string' => \&Bugzilla::Install::Util::install_string,
 
             # These don't work as normal constants.
index 437979c85371749d4cda16d6cb023420ac659d6f..d03cda0eb88a039ed5a001a79c7dfb230130ee79 100644 (file)
@@ -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 = Bugzilla->request_cache->{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
index 5012769ca0b74145ac6c35ae41370484beda95f0..4ada8c0665a87d9ee30c2f0a2d40294c6f7ffacd 100644 (file)
 
 [% PROCESS global/variables.none.tmpl %]
 
-[% field_descs = { "[Bug creation]"          => "[$terms.Bug creation]",
-                   "actual_time"             => "Actual Hours",
-                   "alias"                   => "Alias",
-                   "assigned_to"             => "Assignee",
-                   "attach_data.thedata"     => "Attachment data",
-                   "attachments.description" => "Attachment description",
-                   "attachments.filename"    => "Attachment filename",
-                   "attachments.mimetype"    => "Attachment mime type",
-                   "attachments.ispatch"     => "Attachment is patch",
-                   "attachments.isobsolete"  => "Attachment is obsolete",
-                   "attachments.isprivate"   => "Attachment is private",
-                   "attachments.isurl"       => "Attachment is a URL",
-                   "attachments.submitter"   => "Attachment creator",
-                   "blocked"                 => "Blocks",
-                   "bug_file_loc"            => "URL",
-                   "bug_group"               => "Group",
-                   "bug_id"                  => "$terms.Bug ID",
-                   "bug_severity"            => "Severity",
-                   "bug_status"              => "Status",
-                   "changeddate"             => "Changed",
-                   "cc"                      => "CC",
-                   "classification"          => "Classification",
-                   "cclist_accessible"       => "CC list accessible",
-                   "commenter"               => "Commenter",
-                   "component_id"            => "Component ID",
-                   "component"               => "Component",
-                   "content"                 => "Content",
-                   "creation_ts"             => "Creation date",
-                   "deadline"                => "Deadline",
-                   "delta_ts"                => "Changed",
-                   "dependson"               => "Depends on",
-                   "dup_id"                  => "Duplicate",
-                   "estimated_time"          => "Orig. Est.",
-                   "everconfirmed"           => "Ever confirmed",
-                   "flagtypes.name"          => "Flags",
-                   "keywords"                => "Keywords",
-                   "longdesc"                => "Comment",
-                   "longdescs.isprivate"     => "Comment is private",
-                   "newcc"                   => "CC",
-                   "op_sys"                  => "OS",
-                   "opendate"                => "Opened",
-                   "owner_idle_time"         => "Time Since Assignee Touched",
-                   "percentage_complete"     => "%Complete",
-                   "priority"                => "Priority",
-                   "product_id"              => "Product ID",
-                   "product"                 => "Product",
-                   "qa_contact"              => "QA Contact",
-                   "remaining_time"          => "Hours Left",
-                   "rep_platform"            => "Hardware",
-                   "reporter"                => "Reporter",
-                   "reporter_accessible"     => "Reporter accessible",
-                   "requestees.login_name"   => "Flag Requestee",
-                   "resolution"              => "Resolution",
-                   "see_also"                => "See Also",
-                   "setters.login_name"      => "Flag Setter",
-                   "setting"                 => "Setting",
-                   "settings"                => "Settings",
-                   "short_desc"              => "Summary",
-                   "status_whiteboard"       => "Whiteboard",
-                   "target_milestone"        => "Target Milestone",
-                   "version"                 => "Version",
-                   "votes"                   => "Votes",
-                   "work_time"               => "Hours Worked"} %]
-
-[%# Also include any custom fields or fields which don't have a
-    Description here, by copying their Description from the
-    database. If you want to override this for your language
-    or your installation, just use a hook. %]
-[% UNLESS Param('shutdownhtml') %]
-  [% FOREACH bz_field = bug_fields.values %]
-    [% SET field_descs.${bz_field.name} = bz_field.description
-       IF !field_descs.${bz_field.name}.defined %]
-  [% END %]
-[% END %]
-
 [% SET search_descs = {
   "noop"           => "---",
   "equals"         => "is equal to",
   [% END %]
 [% END %][% END %]
 
+[% IF in_template_var %]
+  [% vars.terms = terms %]
+
+  [%# field_descs is loaded as a global template variable and cached
+    # across all templates--see VARIABLES in Bugzilla/Template.pm.
+    #%]
+  [% vars.field_descs = {
+    "[Bug creation]"          => "[$terms.Bug creation]",
+     "actual_time"             => "Actual Hours",
+     "alias"                   => "Alias",
+     "assigned_to"             => "Assignee",
+     "attach_data.thedata"     => "Attachment data",
+     "attachments.description" => "Attachment description",
+     "attachments.filename"    => "Attachment filename",
+     "attachments.mimetype"    => "Attachment mime type",
+     "attachments.ispatch"     => "Attachment is patch",
+     "attachments.isobsolete"  => "Attachment is obsolete",
+     "attachments.isprivate"   => "Attachment is private",
+     "attachments.isurl"       => "Attachment is a URL",
+     "attachments.submitter"   => "Attachment creator",
+     "blocked"                 => "Blocks",
+     "bug_file_loc"            => "URL",
+     "bug_group"               => "Group",
+     "bug_id"                  => "$terms.Bug ID",
+     "bug_severity"            => "Severity",
+     "bug_status"              => "Status",
+     "changeddate"             => "Changed",
+     "cc"                      => "CC",
+     "classification"          => "Classification",
+     "cclist_accessible"       => "CC list accessible",
+     "commenter"               => "Commenter",
+     "component_id"            => "Component ID",
+     "component"               => "Component",
+     "content"                 => "Content",
+     "creation_ts"             => "Creation date",
+     "deadline"                => "Deadline",
+     "delta_ts"                => "Changed",
+     "dependson"               => "Depends on",
+     "dup_id"                  => "Duplicate",
+     "estimated_time"          => "Orig. Est.",
+     "everconfirmed"           => "Ever confirmed",
+     "flagtypes.name"          => "Flags",
+     "keywords"                => "Keywords",
+     "longdesc"                => "Comment",
+     "longdescs.isprivate"     => "Comment is private",
+     "newcc"                   => "CC",
+     "op_sys"                  => "OS",
+     "opendate"                => "Opened",
+     "owner_idle_time"         => "Time Since Assignee Touched",
+     "percentage_complete"     => "%Complete",
+     "priority"                => "Priority",
+     "product_id"              => "Product ID",
+     "product"                 => "Product",
+     "qa_contact"              => "QA Contact",
+     "remaining_time"          => "Hours Left",
+     "rep_platform"            => "Hardware",
+     "reporter"                => "Reporter",
+     "reporter_accessible"     => "Reporter accessible",
+     "requestees.login_name"   => "Flag Requestee",
+     "resolution"              => "Resolution",
+     "see_also"                => "See Also",
+     "setters.login_name"      => "Flag Setter",
+     "setting"                 => "Setting",
+     "settings"                => "Settings",
+     "short_desc"              => "Summary",
+     "status_whiteboard"       => "Whiteboard",
+     "target_milestone"        => "Target Milestone",
+     "version"                 => "Version",
+     "votes"                   => "Votes"
+     "work_time"               => "Hours Worked",
+  } %]
+
+  [%# Also include any custom fields or fields which don't have a
+      Description here, by copying their Description from the
+      database. If you want to override this for your language
+      or your installation, just use a hook. %]
+  [% UNLESS Param('shutdownhtml') %]
+    [% FOREACH bz_field = bug_fields.values %]
+      [% SET vars.field_descs.${bz_field.name} = bz_field.description
+         IF !vars.field_descs.${bz_field.name}.defined %]
+    [% END %]
+  [% END %]
+[% END %]
+
 [% Hook.process("end") %]