summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Flag.pm
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2008-09-08 23:21:24 +0200
committerlpsolit%gmail.com <>2008-09-08 23:21:24 +0200
commit4dd427ea99673391d923db9682836d344f178b54 (patch)
tree15cac366546a970dfbe8a0ed7163976f09dfbfb2 /Bugzilla/Flag.pm
parent1d66aab134be7002268c4da177bbf4870ac90d6d (diff)
downloadbugzilla-4dd427ea99673391d923db9682836d344f178b54.tar.gz
bugzilla-4dd427ea99673391d923db9682836d344f178b54.tar.xz
Bug 453743: Decrease the number of calls to the DB about flags when viewing a bug - Patch by Frédéric Buclin <LpSolit@gmail.com> r/a=mkanat
Diffstat (limited to 'Bugzilla/Flag.pm')
-rw-r--r--Bugzilla/Flag.pm38
1 files changed, 38 insertions, 0 deletions
diff --git a/Bugzilla/Flag.pm b/Bugzilla/Flag.pm
index 8201a907d..ea3e940d8 100644
--- a/Bugzilla/Flag.pm
+++ b/Bugzilla/Flag.pm
@@ -1158,6 +1158,44 @@ sub CancelRequests {
\@old_summaries, \@new_summaries);
}
+# This is an internal function used by $bug->flag_types
+# and $attachment->flag_types to collect data about available
+# flag types and existing flags set on them. You should never
+# call this function directly.
+sub _flag_types {
+ my $vars = shift;
+
+ my $target_type = $vars->{target_type};
+ my $flags;
+
+ # Retrieve all existing flags for this bug/attachment.
+ if ($target_type eq 'bug') {
+ my $bug_id = delete $vars->{bug_id};
+ $flags = Bugzilla::Flag->match({target_type => 'bug', bug_id => $bug_id});
+ }
+ elsif ($target_type eq 'attachment') {
+ my $attach_id = delete $vars->{attach_id};
+ $flags = Bugzilla::Flag->match({attach_id => $attach_id});
+ }
+ else {
+ ThrowCodeError('bad_arg', {argument => 'target_type',
+ function => 'Bugzilla::Flag::_flag_types'});
+ }
+
+ # Get all available flag types for the given product and component.
+ my $flag_types = Bugzilla::FlagType::match($vars);
+
+ $_->{flags} = [] foreach @$flag_types;
+ my %flagtypes = map { $_->id => $_ } @$flag_types;
+
+ # Group existing flags per type.
+ # Call the internal 'type_id' variable instead of the method
+ # to not create a flagtype object.
+ push(@{$flagtypes{$_->{type_id}}->{flags}}, $_) foreach @$flags;
+
+ return [sort {$a->sortkey <=> $b->sortkey || $a->name cmp $b->name} values %flagtypes];
+}
+
=head1 SEE ALSO
=over