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 @@
module Search
class GlobalService
include Gitlab::Utils::StrongMemoize
attr_accessor :current_user, :params
attr_reader :default_project_filter
......@@ -11,42 +13,26 @@ module Search
end
def execute
if Gitlab::CurrentSettings.elasticsearch_search?
Gitlab::Elastic::SearchResults.new(current_user, params[:search], elastic_projects, elastic_global)
else
Gitlab::SearchResults.new(current_user, projects, params[:search],
default_project_filter: default_project_filter)
end
Gitlab::SearchResults.new(current_user, projects, params[:search],
default_project_filter: default_project_filter)
end
def projects
@projects ||= ProjectsFinder.new(current_user: current_user).execute
end
# rubocop: disable CodeReuse/ActiveRecord
def elastic_projects
@elastic_projects ||=
if current_user&.full_private_access?
:any
elsif current_user
current_user.authorized_projects.pluck(:id)
else
[]
end
end
# rubocop: enable CodeReuse/ActiveRecord
def elastic_global
true
def allowed_scopes
strong_memoize(:allowed_scopes) do
%w[issues merge_requests milestones]
end
end
def scope
@scope ||= begin
allowed_scopes = %w[issues merge_requests milestones]
allowed_scopes += %w[wiki_blobs blobs commits] if Gitlab::CurrentSettings.elasticsearch_search?
allowed_scopes.delete(params[:scope]) { 'projects' }
strong_memoize(:scope) do
allowed_scopes.include?(params[:scope]) ? params[:scope] : 'projects'
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