diff options
author | Markus Koller <mkoller@gitlab.com> | 2019-07-15 20:59:57 +0300 |
---|---|---|
committer | Markus Koller <mkoller@gitlab.com> | 2019-08-12 23:01:15 +0300 |
commit | 49c83155ccb78284b17a9ffa47583ddace5dbd01 (patch) | |
tree | f9b5697ef11d581737d07b395f529ef3d20e1325 /lib/gitlab/search_results.rb | |
parent | 71ec793214dd81701b5485aa10e20c9719cb0584 (diff) |
Load search result counts asynchronously
Querying all counts for the different search results in the same request
led to timeouts, so we now only calculate the count for the *current*
search results, and request the others in separate asynchronous calls.
Diffstat (limited to 'lib/gitlab/search_results.rb')
-rw-r--r-- | lib/gitlab/search_results.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/gitlab/search_results.rb b/lib/gitlab/search_results.rb index 7c1e6b1baff..ce4c1611687 100644 --- a/lib/gitlab/search_results.rb +++ b/lib/gitlab/search_results.rb @@ -43,6 +43,29 @@ module Gitlab without_count ? collection.without_count : collection end + def formatted_count(scope) + case scope + when 'projects' + formatted_limited_count(limited_projects_count) + when 'issues' + formatted_limited_count(limited_issues_count) + when 'merge_requests' + formatted_limited_count(limited_merge_requests_count) + when 'milestones' + formatted_limited_count(limited_milestones_count) + when 'users' + formatted_limited_count(limited_users_count) + end + end + + def formatted_limited_count(count) + if count >= COUNT_LIMIT + "#{COUNT_LIMIT - 1}+" + else + count.to_s + end + end + def limited_projects_count @limited_projects_count ||= limited_count(projects) end |