From: Frédéric Buclin Date: Sun, 5 Apr 2015 19:48:58 +0000 (+0200) Subject: Bug 1143874: Improve load time of bug comments X-Git-Tag: bugzilla-5.0rc3~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2c8f774694bd9782fe3310204b626ea20e43b6e;p=thirdparty%2Fbugzilla.git Bug 1143874: Improve load time of bug comments r=dkl a=sgreen --- diff --git a/Bugzilla/BugMail.pm b/Bugzilla/BugMail.pm index 8b4219787d..9ebf3ea7dd 100644 --- a/Bugzilla/BugMail.pm +++ b/Bugzilla/BugMail.pm @@ -38,9 +38,6 @@ sub relationships { return %relationships; } -# This is a bit of a hack, basically keeping the old system() -# cmd line interface. Should clean this up at some point. -# # args: bug_id, and an optional hash ref which may have keys for: # changer, owner, qa, reporter, cc # Optional hash contains values of people which will be forced to those @@ -88,6 +85,8 @@ sub Send { @diffs = _get_new_bugmail_fields($bug); } + my $comments = []; + if ($params->{dep_only}) { push(@diffs, { field_name => 'bug_status', old => $params->{changes}->{bug_status}->[0], @@ -104,14 +103,14 @@ sub Send { } else { push(@diffs, _get_diffs($bug, $end, \%user_cache)); - } - my $comments = $bug->comments({ after => $start, to => $end }); - # Skip empty comments. - @$comments = grep { $_->type || $_->body =~ /\S/ } @$comments; + $comments = $bug->comments({ after => $start, to => $end }); + # Skip empty comments. + @$comments = grep { $_->type || $_->body =~ /\S/ } @$comments; - # If no changes have been made, there is no need to process further. - return {'sent' => []} unless scalar(@diffs) || scalar(@$comments); + # If no changes have been made, there is no need to process further. + return {'sent' => []} unless scalar(@diffs) || scalar(@$comments); + } ########################################################################### # Start of email filtering code diff --git a/Bugzilla/Comment.pm b/Bugzilla/Comment.pm index c235b8d308..b036907d74 100644 --- a/Bugzilla/Comment.pm +++ b/Bugzilla/Comment.pm @@ -160,11 +160,15 @@ sub preload { my $rows = $dbh->selectall_arrayref( "SELECT comment_id, " . $dbh->sql_group_concat('tag', "','") . " FROM longdescs_tags - WHERE " . $dbh->sql_in('comment_id', \@comment_ids) . " - GROUP BY comment_id"); + WHERE " . $dbh->sql_in('comment_id', \@comment_ids) . ' ' . + $dbh->sql_group_by('comment_id')); foreach my $row (@$rows) { $comment_map{$row->[0]}->{tags} = [ split(/,/, $row->[1]) ]; } + # Also sets the 'tags' attribute for comments which have no entry + # in the longdescs_tags table, else calling $comment->tags will + # trigger another SQL query again. + $comment_map{$_}->{tags} ||= [] foreach @comment_ids; } } @@ -187,7 +191,8 @@ sub extra_data { return $_[0]->{'extra_data'} } sub tags { my ($self) = @_; - return [] unless Bugzilla->params->{'comment_taggers_group'}; + state $comment_taggers_group = Bugzilla->params->{'comment_taggers_group'}; + return [] unless $comment_taggers_group; $self->{'tags'} ||= Bugzilla->dbh->selectcol_arrayref( "SELECT tag FROM longdescs_tags @@ -199,11 +204,14 @@ sub tags { sub collapsed { my ($self) = @_; - return 0 unless Bugzilla->params->{'comment_taggers_group'}; + state $comment_taggers_group = Bugzilla->params->{'comment_taggers_group'}; + return 0 unless $comment_taggers_group; return $self->{collapsed} if exists $self->{collapsed}; + + state $collapsed_comment_tags = Bugzilla->params->{'collapsed_comment_tags'}; $self->{collapsed} = 0; Bugzilla->request_cache->{comment_tags_collapsed} - ||= [ split(/\s*,\s*/, Bugzilla->params->{'collapsed_comment_tags'}) ]; + ||= [ split(/\s*,\s*/, $collapsed_comment_tags) ]; my @collapsed_tags = @{ Bugzilla->request_cache->{comment_tags_collapsed} }; foreach my $my_tag (@{ $self->tags }) { $my_tag = lc($my_tag); diff --git a/template/en/default/bug/comments.html.tmpl b/template/en/default/bug/comments.html.tmpl index d040e651d1..f4f79ec5c0 100644 --- a/template/en/default/bug/comments.html.tmpl +++ b/template/en/default/bug/comments.html.tmpl @@ -46,6 +46,7 @@ [% DEFAULT mode = "show" %] [% user_cache = template_cache.users %] +[% can_edit_comments = bug.check_can_change_field('longdesc', 0, 1) %] @@ -53,9 +54,7 @@ -[% FOREACH comment = comments %] - [% PROCESS a_comment %] -[% END %] +[% PROCESS display_comments %] [% IF mode == "edit" && user.id && user.settings.comment_box_position.value == "before_comments" %] @@ -96,10 +95,11 @@ [%# Block for individual comments #%] [%############################################################################%] -[% BLOCK a_comment %] - [% RETURN IF comment.is_private AND NOT (user.is_insider || user.id == comment.author.id) %] - [% comment_text = comment.body_full %] - [% RETURN IF comment_text == '' AND (comment.work_time - 0) != 0 AND !user.is_timetracker %] +[% BLOCK display_comments %] + [% FOREACH comment = comments %] + [% NEXT IF comment.is_private AND NOT (user.is_insider || user.id == comment.author.id) %] + [% comment_text = comment.body_full %] + [% NEXT IF comment_text == '' AND (comment.work_time - 0) != 0 AND !user.is_timetracker %]
[% END %] - [% IF bug.check_can_change_field('longdesc', 0, 1) %] + [% IF can_edit_comments %] [% IF user.can_tag_comments %] [tag] @@ -145,7 +145,7 @@ [% END %] - [% IF mode == "edit" && user.is_insider && bug.check_can_change_field('longdesc', 0, 1) %] + [% IF mode == "edit" && can_edit_comments && user.is_insider %]
@@ -233,4 +233,5 @@ [% Hook.process('a_comment-end', 'bug/comments.html.tmpl') %]
+ [% END %] [% END %]