Commit 6bdf92f0 authored by Dylan Griffith's avatar Dylan Griffith Committed by Mark Chao

Remove an N+1 call rendering projects search results

parent 26ccbc3e
......@@ -44,6 +44,14 @@ module UsersHelper
current_user_menu_items.include?(item)
end
# Used to preload when you are rendering many projects and checking access
#
# rubocop: disable CodeReuse/ActiveRecord: `projects` can be array which also responds to pluck
def load_max_project_member_accesses(projects)
current_user&.max_member_access_for_project_ids(projects.pluck(:id))
end
# rubocop: enable CodeReuse/ActiveRecord
def max_project_member_access(project)
current_user&.max_member_access_for_project(project.id) || Gitlab::Access::NO_ACCESS
end
......
......@@ -35,6 +35,7 @@
.js-projects-list-holder{ data: { qa_selector: 'projects_list' } }
- if any_projects?(projects)
- load_pipeline_status(projects) if pipeline_status
- load_max_project_member_accesses(projects) # Prime cache used in shared/projects/project view rendered below
%ul.projects-list{ class: css_classes }
- projects.each_with_index do |project, i|
- css_class = (i >= projects_limit) || project.pending_delete? ? 'hide' : nil
......
---
title: Remove an N+1 call rendering projects search results
merge_request: 21626
author:
type: performance
......@@ -43,10 +43,10 @@ describe 'Global elastic search', :elastic do
let(:object) { :project }
let(:creation_args) { { namespace: user.namespace } }
let(:path) { search_path(search: 'project*', scope: 'projects') }
# Each Project requires 5 extra queries: one for each "count" (forks,
# open MRs, open Issues) and twice for access level. This should be fixed
# per https://gitlab.com/gitlab-org/gitlab/issues/34457
let(:query_count_multiplier) { 5 }
# Each Project requires 4 extra queries: one for each "count" (forks,
# open MRs, open Issues and access levels). This should be fixed per
# https://gitlab.com/gitlab-org/gitlab/issues/34457
let(:query_count_multiplier) { 4 }
it_behaves_like 'an efficient database result'
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