From 107ebb8251463cef43b6ccf00dde4de54d66d1ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Javier=20L=C3=B3pez?= Date: Mon, 9 Sep 2019 13:46:24 +0000 Subject: [PATCH] Lower searches count limit Lowering the limit when performing search from 1001 to 101. This will allow us to speed this process. --- .../fj-11777-lower-search-count-limits.yml | 5 +++++ lib/gitlab/search_results.rb | 5 +++-- spec/lib/gitlab/project_search_results_spec.rb | 6 ++++-- spec/lib/gitlab/search_results_spec.rb | 17 +++++++++-------- spec/lib/gitlab/snippet_search_results_spec.rb | 4 +++- spec/support/helpers/search_helpers.rb | 4 ++++ 6 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 changelogs/unreleased/fj-11777-lower-search-count-limits.yml diff --git a/changelogs/unreleased/fj-11777-lower-search-count-limits.yml b/changelogs/unreleased/fj-11777-lower-search-count-limits.yml new file mode 100644 index 00000000000..c284bc49bfc --- /dev/null +++ b/changelogs/unreleased/fj-11777-lower-search-count-limits.yml @@ -0,0 +1,5 @@ +--- +title: Lower search counters +merge_request: 11777 +author: +type: performance diff --git a/lib/gitlab/search_results.rb b/lib/gitlab/search_results.rb index ce4c1611687..93e172299b9 100644 --- a/lib/gitlab/search_results.rb +++ b/lib/gitlab/search_results.rb @@ -2,7 +2,8 @@ module Gitlab class SearchResults - COUNT_LIMIT = 1001 + COUNT_LIMIT = 101 + COUNT_LIMIT_MESSAGE = "#{COUNT_LIMIT - 1}+" attr_reader :current_user, :query, :per_page @@ -60,7 +61,7 @@ module Gitlab def formatted_limited_count(count) if count >= COUNT_LIMIT - "#{COUNT_LIMIT - 1}+" + COUNT_LIMIT_MESSAGE else count.to_s end diff --git a/spec/lib/gitlab/project_search_results_spec.rb b/spec/lib/gitlab/project_search_results_spec.rb index 0dbfcf96124..e0b9581c75c 100644 --- a/spec/lib/gitlab/project_search_results_spec.rb +++ b/spec/lib/gitlab/project_search_results_spec.rb @@ -4,6 +4,8 @@ require 'spec_helper' describe Gitlab::ProjectSearchResults do + include SearchHelpers + let(:user) { create(:user) } let(:project) { create(:project) } let(:query) { 'hello world' } @@ -31,10 +33,10 @@ describe Gitlab::ProjectSearchResults do where(:scope, :count_method, :expected) do 'blobs' | :blobs_count | '1234' - 'notes' | :limited_notes_count | '1000+' + 'notes' | :limited_notes_count | max_limited_count 'wiki_blobs' | :wiki_blobs_count | '1234' 'commits' | :commits_count | '1234' - 'projects' | :limited_projects_count | '1000+' + 'projects' | :limited_projects_count | max_limited_count 'unknown' | nil | nil end diff --git a/spec/lib/gitlab/search_results_spec.rb b/spec/lib/gitlab/search_results_spec.rb index 5621c686b8a..26cba53502d 100644 --- a/spec/lib/gitlab/search_results_spec.rb +++ b/spec/lib/gitlab/search_results_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' describe Gitlab::SearchResults do include ProjectForksHelper + include SearchHelpers let(:user) { create(:user) } let!(:project) { create(:project, name: 'foo') } @@ -35,11 +36,11 @@ describe Gitlab::SearchResults do using RSpec::Parameterized::TableSyntax where(:scope, :count_method, :expected) do - 'projects' | :limited_projects_count | '1000+' - 'issues' | :limited_issues_count | '1000+' - 'merge_requests' | :limited_merge_requests_count | '1000+' - 'milestones' | :limited_milestones_count | '1000+' - 'users' | :limited_users_count | '1000+' + 'projects' | :limited_projects_count | max_limited_count + 'issues' | :limited_issues_count | max_limited_count + 'merge_requests' | :limited_merge_requests_count | max_limited_count + 'milestones' | :limited_milestones_count | max_limited_count + 'users' | :limited_users_count | max_limited_count 'unknown' | nil | nil end @@ -56,9 +57,9 @@ describe Gitlab::SearchResults do where(:count, :expected) do 23 | '23' - 1000 | '1000' - 1001 | '1000+' - 1234 | '1000+' + 100 | '100' + 101 | max_limited_count + 1234 | max_limited_count end with_them do diff --git a/spec/lib/gitlab/snippet_search_results_spec.rb b/spec/lib/gitlab/snippet_search_results_spec.rb index 89d290aaa81..d3353b76c15 100644 --- a/spec/lib/gitlab/snippet_search_results_spec.rb +++ b/spec/lib/gitlab/snippet_search_results_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' describe Gitlab::SnippetSearchResults do + include SearchHelpers + let!(:snippet) { create(:snippet, content: 'foo', file_name: 'foo') } let(:results) { described_class.new(Snippet.all, 'foo') } @@ -25,7 +27,7 @@ describe Gitlab::SnippetSearchResults do where(:scope, :count_method, :expected) do 'snippet_titles' | :snippet_titles_count | '1234' 'snippet_blobs' | :snippet_blobs_count | '1234' - 'projects' | :limited_projects_count | '1000+' + 'projects' | :limited_projects_count | max_limited_count 'unknown' | nil | nil end diff --git a/spec/support/helpers/search_helpers.rb b/spec/support/helpers/search_helpers.rb index 2cf3f4b83c4..d1d25fbabcd 100644 --- a/spec/support/helpers/search_helpers.rb +++ b/spec/support/helpers/search_helpers.rb @@ -19,4 +19,8 @@ module SearchHelpers click_link scope end end + + def max_limited_count + Gitlab::SearchResults::COUNT_LIMIT_MESSAGE + end end