diff options
author | Markus Koller <mkoller@gitlab.com> | 2019-07-15 19:59:57 +0200 |
---|---|---|
committer | Markus Koller <mkoller@gitlab.com> | 2019-08-12 22:01:15 +0200 |
commit | 49c83155ccb78284b17a9ffa47583ddace5dbd01 (patch) | |
tree | f9b5697ef11d581737d07b395f529ef3d20e1325 /app/helpers | |
parent | 71ec793214dd81701b5485aa10e20c9719cb0584 (diff) | |
download | gitlab-ce-49c83155ccb78284b17a9ffa47583ddace5dbd01.tar.gz |
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 'app/helpers')
-rw-r--r-- | app/helpers/search_helper.rb | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index f5c4686a3bf..add4e555c70 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -145,17 +145,28 @@ module SearchHelper Sanitize.clean(str) end - def search_filter_path(options = {}) - exist_opts = { - search: params[:search], - project_id: params[:project_id], - group_id: params[:group_id], - scope: params[:scope], - repository_ref: params[:repository_ref] - } + def search_filter_link(scope, label, data: {}, search: {}) + search_params = params + .merge(search) + .merge({ scope: scope }) + .permit(:search, :scope, :project_id, :group_id, :repository_ref, :snippets) + + if @scope == scope + li_class = 'active' + count = @search_results.formatted_count(scope) + else + count = 0 + badge_class = 'js-search-count' + badge_data = { scope: scope, url: search_count_path(search_params) } + end - options = exist_opts.merge(options) - search_path(options) + content_tag :li, class: li_class, data: data do + link_to search_path(search_params) do + concat label + concat ' ' + concat content_tag(:span, count, class: 'badge badge-pill', data: { scope: scope }) + end + end end def search_filter_input_options(type) @@ -212,10 +223,6 @@ module SearchHelper sanitize(html, tags: %w(a p ol ul li pre code)) end - def limited_count(count, limit = 1000) - count > limit ? "#{limit}+" : count - end - def search_tabs?(tab) return false if Feature.disabled?(:users_search, default_enabled: true) |