Commit e4cd90fd authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'reduce-diff-in-search-global_service' into 'master'

[EE] Reduce diff with CE in Search::GlobalService

See merge request gitlab-org/gitlab-ee!9427
parents e93fc2f5 661c1cff
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
module Search module Search
class GlobalService class GlobalService
include Gitlab::Utils::StrongMemoize
attr_accessor :current_user, :params attr_accessor :current_user, :params
attr_reader :default_project_filter attr_reader :default_project_filter
...@@ -11,42 +13,26 @@ module Search ...@@ -11,42 +13,26 @@ module Search
end end
def execute def execute
if Gitlab::CurrentSettings.elasticsearch_search? Gitlab::SearchResults.new(current_user, projects, params[:search],
Gitlab::Elastic::SearchResults.new(current_user, params[:search], elastic_projects, elastic_global) default_project_filter: default_project_filter)
else
Gitlab::SearchResults.new(current_user, projects, params[:search],
default_project_filter: default_project_filter)
end
end end
def projects def projects
@projects ||= ProjectsFinder.new(current_user: current_user).execute @projects ||= ProjectsFinder.new(current_user: current_user).execute
end end
# rubocop: disable CodeReuse/ActiveRecord def allowed_scopes
def elastic_projects strong_memoize(:allowed_scopes) do
@elastic_projects ||= %w[issues merge_requests milestones]
if current_user&.full_private_access? end
:any
elsif current_user
current_user.authorized_projects.pluck(:id)
else
[]
end
end
# rubocop: enable CodeReuse/ActiveRecord
def elastic_global
true
end end
def scope def scope
@scope ||= begin strong_memoize(:scope) do
allowed_scopes = %w[issues merge_requests milestones] allowed_scopes.include?(params[:scope]) ? params[:scope] : 'projects'
allowed_scopes += %w[wiki_blobs blobs commits] if Gitlab::CurrentSettings.elasticsearch_search?
allowed_scopes.delete(params[:scope]) { 'projects' }
end end
end end
end end
end end
Search::GlobalService.prepend(EE::Search::GlobalService)
# frozen_string_literal: true
module EE
module Search
module GlobalService
extend ::Gitlab::Utils::Override
include ::Gitlab::Utils::StrongMemoize
override :execute
def execute
if ::Gitlab::CurrentSettings.elasticsearch_search?
::Gitlab::Elastic::SearchResults.new(current_user, params[:search], elastic_projects, elastic_global)
else
super
end
end
def elastic_projects
strong_memoize(:elastic_projects) do
if current_user&.full_private_access?
:any
elsif current_user
current_user.authorized_projects.pluck(:id) # rubocop: disable CodeReuse/ActiveRecord
else
[]
end
end
end
def elastic_global
true
end
override :allowed_scopes
def allowed_scopes
strong_memoize(:ee_allowed_scopes) do
super.tap do |ce_scopes|
ce_scopes.concat(%w[wiki_blobs blobs commits]) if ::Gitlab::CurrentSettings.elasticsearch_search?
end
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment