]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 364162: Code determining if named queries should be shown in the page footer...
authorlpsolit%gmail.com <>
Sun, 9 Nov 2008 01:03:32 +0000 (01:03 +0000)
committerlpsolit%gmail.com <>
Sun, 9 Nov 2008 01:03:32 +0000 (01:03 +0000)
Bugzilla/Search/Saved.pm
Bugzilla/User.pm

index 9aa27714d3f237cb55d8a6c5cc475884ed999b74..c8322242bcf03cdbad5a855cc1ebda4a25c64ea6 100644 (file)
@@ -117,6 +117,24 @@ sub create {
     return $obj;
 }
 
+sub preload {
+    my ($searches) = @_;
+    my $dbh = Bugzilla->dbh;
+
+    return unless scalar @$searches;
+
+    my @query_ids = map { $_->id } @$searches;
+    my $queries_in_footer = $dbh->selectcol_arrayref(
+        'SELECT namedquery_id
+           FROM namedqueries_link_in_footer
+          WHERE ' . $dbh->sql_in('namedquery_id', \@query_ids) . ' AND user_id = ?',
+          undef, Bugzilla->user->id);
+
+    my %links_in_footer = map { $_ => 1 } @$queries_in_footer;
+    foreach my $query (@$searches) {
+        $query->{link_in_footer} = ($links_in_footer{$query->id}) ? 1 : 0;
+    }
+}
 #####################
 # Complex Accessors #
 #####################
@@ -250,6 +268,12 @@ Does not accept a bare C<name> argument. Instead, accepts only an id.
 
 See also: L<Bugzilla::Object/new>.
 
+=item C<preload>
+
+Sets C<link_in_footer> for all given saved searches at once, for the
+currently logged in user. This is much faster than calling this method
+for each saved search individually.
+
 =back
 
 
index 91240e1ceb27dab884fc5300eb092f0047a843c2..41ded04679f436814089873a4a97e0cb49e2ab6d 100644 (file)
@@ -281,6 +281,11 @@ sub queries {
         'SELECT id FROM namedqueries WHERE userid = ?', undef, $self->id);
     require Bugzilla::Search::Saved;
     $self->{queries} = Bugzilla::Search::Saved->new_from_list($query_ids);
+
+    # We preload link_in_footer from here as this information is always requested.
+    # This only works if the user object represents the current logged in user.
+    Bugzilla::Search::Saved::preload($self->{queries}) if $self->id == Bugzilla->user->id;
+
     return $self->{queries};
 }