From b1886835c81c014c1423fa2f2d83e157cbde1406 Mon Sep 17 00:00:00 2001 From: Frédéric Buclin Date: Sun, 5 Apr 2015 21:46:33 +0200 Subject: Bug 1143874: Improve load time of bug comments r=dkl a=sgreen --- Bugzilla/Comment.pm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'Bugzilla/Comment.pm') diff --git a/Bugzilla/Comment.pm b/Bugzilla/Comment.pm index 3dabe6702..8232f5ac1 100644 --- a/Bugzilla/Comment.pm +++ b/Bugzilla/Comment.pm @@ -162,11 +162,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; } } @@ -190,7 +194,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 @@ -202,11 +207,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); -- cgit v1.2.3-24-g4f1b