From 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 18 Jun 2020 11:18:50 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-1-stable-ee --- app/controllers/search_controller.rb | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'app/controllers/search_controller.rb') diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 04d2b3068da..217f08dd648 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -5,6 +5,10 @@ class SearchController < ApplicationController include SearchHelper include RendersCommits + SCOPE_PRELOAD_METHOD = { + projects: :with_web_entity_associations + }.freeze + around_action :allow_gitaly_ref_name_caching skip_before_action :authenticate_user! @@ -28,12 +32,12 @@ class SearchController < ApplicationController @scope = search_service.scope @show_snippets = search_service.show_snippets? @search_results = search_service.search_results - @search_objects = search_service.search_objects + @search_objects = search_service.search_objects(preload_method) render_commits if @scope == 'commits' eager_load_user_status if @scope == 'users' - increment_navbar_searches_counter + increment_search_counters check_single_commit_result end @@ -47,22 +51,11 @@ class SearchController < ApplicationController render json: { count: count } end - # rubocop: disable CodeReuse/ActiveRecord - def autocomplete - term = params[:term] - - if params[:project_id].present? - @project = Project.find_by(id: params[:project_id]) - @project = nil unless can?(current_user, :read_project, @project) - end - - @ref = params[:project_ref] if params[:project_ref].present? + private - render json: search_autocomplete_opts(term).to_json + def preload_method + SCOPE_PRELOAD_METHOD[@scope.to_sym] end - # rubocop: enable CodeReuse/ActiveRecord - - private def search_term_valid? unless search_service.valid_query_length? @@ -98,9 +91,11 @@ class SearchController < ApplicationController end end - def increment_navbar_searches_counter + def increment_search_counters + Gitlab::UsageDataCounters::SearchCounter.count(:all_searches) + return if params[:nav_source] != 'navbar' - Gitlab::UsageDataCounters::SearchCounter.increment_navbar_searches_count + Gitlab::UsageDataCounters::SearchCounter.count(:navbar_searches) end end -- cgit v1.2.1