Skip to content
Snippets Groups Projects

Improve performance of the global search for issuables

All threads resolved!
Compare and Show latest version
10 files
+ 82
91
Compare changes
  • Side-by-side
  • Inline
Files
10
@@ -30,7 +30,6 @@
@@ -30,7 +30,6 @@
# updated_before: datetime
# updated_before: datetime
# attempt_group_search_optimizations: boolean
# attempt_group_search_optimizations: boolean
# attempt_project_search_optimizations: boolean
# attempt_project_search_optimizations: boolean
# attempt_global_search_optimizations: boolean
#
#
class IssuableFinder
class IssuableFinder
prepend FinderWithCrossProjectAccess
prepend FinderWithCrossProjectAccess
@@ -197,10 +196,10 @@ def projects
@@ -197,10 +196,10 @@ def projects
elsif group
elsif group
find_group_projects
find_group_projects
else
else
find_projects
Project.public_or_visible_to_user(current_user, min_access_level)
end
end
@projects = projects.with_feature_available_for_user(klass, current_user)
@projects = projects.with_feature_available_for_user(klass, current_user).reorder(nil) # rubocop: disable CodeReuse/ActiveRecord
end
end
def find_group_projects
def find_group_projects
@@ -212,11 +211,6 @@ def find_group_projects
@@ -212,11 +211,6 @@ def find_group_projects
params: { min_access_level: min_access_level }).execute
params: { min_access_level: min_access_level }).execute
end
end
def find_projects
ProjectsFinder.new(current_user: current_user, # rubocop: disable CodeReuse/Finder
params: { public_or_min_access_level: min_access_level }).execute
end
def search
def search
params[:search].presence
params[:search].presence
end
end
@@ -330,9 +324,7 @@ def use_cte_for_search?
@@ -330,9 +324,7 @@ def use_cte_for_search?
# Only simple unsorted & simple sorts can use CTE
# Only simple unsorted & simple sorts can use CTE
next false if params[:sort].present? && !params[:sort].in?(klass.simple_sorts.keys)
next false if params[:sort].present? && !params[:sort].in?(klass.simple_sorts.keys)
attempt_group_search_optimizations? ||
attempt_group_search_optimizations? || attempt_project_search_optimizations?
attempt_project_search_optimizations? ||
attempt_global_search_optimizations?
end
end
end
end
@@ -356,11 +348,6 @@ def attempt_project_search_optimizations?
@@ -356,11 +348,6 @@ def attempt_project_search_optimizations?
Feature.enabled?(:attempt_project_search_optimizations)
Feature.enabled?(:attempt_project_search_optimizations)
end
end
def attempt_global_search_optimizations?
params[:attempt_global_search_optimizations] &&
Feature.enabled?(:attempt_global_search_optimizations)
end
def count_key(value)
def count_key(value)
Array(value).last.to_sym
Array(value).last.to_sym
end
end
@@ -434,8 +421,9 @@ def by_project(items)
@@ -434,8 +421,9 @@ def by_project(items)
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_search(items)
def by_search(items)
return items unless search
return items unless search
 
return items if items == Issue.none
if use_cte_for_search? && items != ApplicationRecord.none
if use_cte_for_search?
cte = Gitlab::SQL::RecursiveCTE.new(klass.table_name)
cte = Gitlab::SQL::RecursiveCTE.new(klass.table_name)
cte << items
cte << items
Loading