Commit a061a454 authored by Stan Hu's avatar Stan Hu

Restrict use of CTE fence to dashboards/projects#index

In https://gitlab.com/gitlab-org/gitlab/merge_requests/23754, we added a
CTE optimization fence to ensure loading a user's projects is always
fast.

However, using a CTE for the dashboard/projects/starred endpoint is less
efficient than the default query because that endpoint also loads public
and internal projects. For now, we can just restrict use of this CTE for
the `index` action.

In the future, we may want to put this logic inside ProjectsFinder.

Closes https://gitlab.com/gitlab-org/gitlab/issues/201994
parent 6180d91a
......@@ -66,7 +66,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
@total_user_projects_count = ProjectsFinder.new(params: { non_public: true }, current_user: current_user).execute
@total_starred_projects_count = ProjectsFinder.new(params: { starred: true }, current_user: current_user).execute
finder_params[:use_cte] = Feature.enabled?(:use_cte_for_projects_finder, default_enabled: true)
finder_params[:use_cte] = true if use_cte_for_finder?
projects = ProjectsFinder
.new(params: finder_params, current_user: current_user)
......@@ -79,6 +79,11 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end
# rubocop: enable CodeReuse/ActiveRecord
def use_cte_for_finder?
# The starred action loads public projects, which causes the CTE to be less efficient
action_name == 'index' && Feature.enabled?(:use_cte_for_projects_finder, default_enabled: true)
end
def load_events
projects = load_projects(params.merge(non_public: true))
......
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