From 3d49752f959fd6c2b5e88eef8333b15705614f68 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Thu, 26 Sep 2013 00:17:52 +0800 Subject: Bug 920060: Bug.search API doesn't return total results --- Bugzilla/Search.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'Bugzilla/Search.pm') diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index aff189c43..f51a12372 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -753,6 +753,9 @@ sub data { # Restore the original 'fields' argument, just in case. $self->{fields} = \@orig_fields unless $all_in_bugs_table; + # BMO if the caller only wants the count, that's all we need to return + return $bug_ids->[0]->[0] if $self->_params->{count_only}; + # If there are no bugs found, or all fields are in the 'bugs' table, # there is no need for another query. if (!scalar @$bug_ids || $all_in_bugs_table) { @@ -811,7 +814,15 @@ sub _sql { ? "\nORDER BY " . join(', ', $self->_sql_order_by) : ''; my $limit = $self->_sql_limit; $limit = "\n$limit" if $limit; - + + # BMO allow fetching just the number of matching bugs + if ($self->_params->{count_only}) { + $select = 'COUNT(*) AS count'; + $group_by = ''; + $order_by = ''; + $limit = ''; + } + my $query = <