]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 552168: Speed up comment display by pre-loading all Bugzilla::User
authorMax Kanat-Alexander <mkanat@bugzilla.org>
Sun, 14 Mar 2010 00:41:44 +0000 (16:41 -0800)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Sun, 14 Mar 2010 00:41:44 +0000 (16:41 -0800)
objects for the comment authors, for the whole list, all at once.
r=LpSolit, a=LpSolit

Bugzilla/Bug.pm
Bugzilla/Comment.pm

index fd28b5b82c2324896d4f8f4c16d24a2b9de26f5f..f41a242f9531c5afa78343b0554397efb96364fb 100644 (file)
@@ -2689,6 +2689,7 @@ sub comments {
             $comment->{count} = $count++;
             $comment->{bug} = $self;
         }
+        Bugzilla::Comment->preload($self->{'comments'});
     }
     my @comments = @{ $self->{'comments'} };
 
index 58e1e7a7332d384af6c4a324acaceaa5702d7424..cbdddba3c09a6abb7230c9868e6f0cebc65e63d6 100644 (file)
@@ -27,6 +27,7 @@ use base qw(Bugzilla::Object);
 use Bugzilla::Attachment;
 use Bugzilla::Constants;
 use Bugzilla::Error;
+use Bugzilla::User;
 use Bugzilla::Util;
 
 ###############################
@@ -74,6 +75,18 @@ sub update {
     return $changes;
 }
 
+# Speeds up displays of comment lists by loading all ->author objects
+# at once for a whole list.
+sub preload {
+    my ($class, $comments) = @_;
+    my %user_ids = map { $_->{who} => 1 } @$comments;
+    my $users = Bugzilla::User->new_from_list([keys %user_ids]);
+    my %user_map = map { $_->id => $_ } @$users;
+    foreach my $comment (@$comments) {
+        $comment->{author} = $user_map{$comment->{who}};
+    }
+}
+
 ###############################
 ####      Accessors      ######
 ###############################