Fix N+1 in REST projects and service desk

parent ba77e7d7
---
title: Fix N+1 in REST projects and service desk
merge_request: 58747
author:
type: performance
......@@ -132,6 +132,7 @@ module API
.preload(:project_setting)
.preload(:container_expiration_policy)
.preload(:auto_devops)
.preload(:service_desk_setting)
.preload(project_group_links: { group: :route },
fork_network: :root_project,
fork_network_member: :forked_from_project,
......
......@@ -835,6 +835,29 @@ RSpec.describe API::Projects do
end.not_to exceed_query_limit(control.count)
end
end
context 'when service desk is enabled', :use_clean_rails_memory_store_caching do
let_it_be(:admin) { create(:admin) }
it 'avoids N+1 queries' do
allow(Gitlab::ServiceDeskEmail).to receive(:enabled?).and_return(true)
allow(Gitlab::IncomingEmail).to receive(:enabled?).and_return(true)
get api('/projects', admin)
create(:project, :public, :service_desk_enabled, namespace: admin.namespace)
control = ActiveRecord::QueryRecorder.new do
get api('/projects', admin)
end
create_list(:project, 2, :public, :service_desk_enabled, namespace: admin.namespace)
expect do
get api('/projects', admin)
end.not_to exceed_query_limit(control.count)
end
end
end
describe 'POST /projects' do
......
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