summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorDave Lawrence <dlawrence@mozilla.com>2014-01-03 00:21:36 +0100
committerDave Lawrence <dlawrence@mozilla.com>2014-01-03 00:21:36 +0100
commit32466314c46ac7fd87c411a4aa01691e75cab6a5 (patch)
tree5b8052566604fd68e3a01af5957303c145e6022c /Bugzilla
parent05efc5cc95012761732f453211ccb18456fd8086 (diff)
downloadbugzilla-32466314c46ac7fd87c411a4aa01691e75cab6a5.tar.gz
bugzilla-32466314c46ac7fd87c411a4aa01691e75cab6a5.tar.xz
Bug 945535 - When loading bugs with large number of attachments, $bug->attachments reloads all flags for each attachment even if preloaded
r=LpSolit,a=sgreen
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Attachment.pm36
1 files changed, 21 insertions, 15 deletions
diff --git a/Bugzilla/Attachment.pm b/Bugzilla/Attachment.pm
index ef4785633..c0521c9b4 100644
--- a/Bugzilla/Attachment.pm
+++ b/Bugzilla/Attachment.pm
@@ -45,6 +45,7 @@ use Bugzilla::Hook;
use File::Copy;
use List::Util qw(max);
+use Storable qw(dclone);
use parent qw(Bugzilla::Object);
@@ -653,23 +654,27 @@ sub get_attachments_by_bug {
my $attachments = Bugzilla::Attachment->new_from_list($attach_ids);
$_->{bug} = $bug foreach @$attachments;
- # To avoid $attachment->flags to run SQL queries itself for each
- # attachment listed here, we collect all the data at once and
- # populate $attachment->{flags} ourselves.
- # We also load all attachers and datasizes at once for the same reason.
+ # To avoid $attachment->flags and $attachment->flag_types running SQL queries
+ # themselves for each attachment listed here, we collect all the data at once and
+ # populate $attachment->{flag_types} ourselves. We also load all attachers and
+ # datasizes at once for the same reason.
if ($vars->{preload}) {
- # Preload flags.
- $_->{flags} = [] foreach @$attachments;
- my %att = map { $_->id => $_ } @$attachments;
+ # Preload flag types and flags
+ my $vars = { target_type => 'attachment',
+ product_id => $bug->product_id,
+ component_id => $bug->component_id,
+ attach_id => $attach_ids };
+ my $flag_types = Bugzilla::Flag->_flag_types($vars);
- my $flags = Bugzilla::Flag->match({ bug_id => $bug->id,
- target_type => 'attachment' });
-
- # Exclude flags for private attachments you cannot see.
- @$flags = grep {exists $att{$_->attach_id}} @$flags;
-
- push(@{$att{$_->attach_id}->{flags}}, $_) foreach @$flags;
- $attachments = [sort {$a->id <=> $b->id} values %att];
+ foreach my $attachment (@$attachments) {
+ $attachment->{flag_types} = [];
+ my $new_types = dclone($flag_types);
+ foreach my $new_type (@$new_types) {
+ $new_type->{flags} = [ grep($_->attach_id == $attachment->id,
+ @{ $new_type->{flags} }) ];
+ push(@{ $attachment->{flag_types} }, $new_type);
+ }
+ }
# Preload attachers.
my %user_ids = map { $_->{submitter_id} => 1 } @$attachments;
@@ -689,6 +694,7 @@ sub get_attachments_by_bug {
# Force the size of attachments not in the DB to be recalculated.
$_->{datasize} = $sizes->{$_->id}->{datasize} || undef foreach @$attachments;
}
+
return $attachments;
}