diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-03-05 16:25:56 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-03-05 16:25:56 +0300 |
commit | 741caf93e14758c223b6ef819390f5889bdd108b (patch) | |
tree | 3dcd6e8377b6688eed28e4a24a92cb4ba902ede6 /lib/gitlab/project_search_results.rb | |
parent | f56de375f756ffc4ba4aa76f0cada1a64c45d759 (diff) |
Use limited count queries also for scoped searches
Diffstat (limited to 'lib/gitlab/project_search_results.rb')
-rw-r--r-- | lib/gitlab/project_search_results.rb | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb index cf0935dbd9a..29277ec6481 100644 --- a/lib/gitlab/project_search_results.rb +++ b/lib/gitlab/project_search_results.rb @@ -29,8 +29,18 @@ module Gitlab @blobs_count ||= blobs.count end - def notes_count - @notes_count ||= notes.count + def limited_notes_count + return @limited_notes_count if defined?(@limited_notes_count) + + types = %w(issue merge_request commit snippet) + @limited_notes_count = 0 + + types.each do |type| + @limited_notes_count += notes_finder(type).limit(count_limit).count + break if @limited_notes_count >= count_limit + end + + @limited_notes_count end def wiki_blobs_count @@ -72,11 +82,12 @@ module Gitlab end def single_commit_result? - commits_count == 1 && total_result_count == 1 - end + return false if commits_count != 1 - def total_result_count - issues_count + merge_requests_count + milestones_count + notes_count + blobs_count + wiki_blobs_count + commits_count + counts = %i(limited_milestones_count limited_notes_count + limited_merge_requests_count limited_issues_count + blobs_count wiki_blobs_count) + counts.all? { |count_method| public_send(count_method).zero? } # rubocop:disable GitlabSecurity/PublicSend end private @@ -106,7 +117,11 @@ module Gitlab end def notes - @notes ||= NotesFinder.new(project, @current_user, search: query).execute.user.order('updated_at DESC') + @notes ||= notes_finder(nil) + end + + def notes_finder(type) + NotesFinder.new(project, @current_user, search: query, target_type: type).execute.user.order('updated_at DESC') end def commits |