Commit 2017c5c6 authored by Sean McGivern's avatar Sean McGivern

Fix routes N+1 in Issues::ReferencedMergeRequestsService#execute

Sorting here needs the project routes to be loaded, including the namespace
routes.
parent 22d8fbac
...@@ -14,11 +14,12 @@ module Banzai ...@@ -14,11 +14,12 @@ module Banzai
# Eager loading these ensures we don't end up running dozens of # Eager loading these ensures we don't end up running dozens of
# queries in this process. # queries in this process.
target_project: [ target_project: [
{ namespace: :owner }, { namespace: [:owner, :route] },
{ group: [:owners, :group_members] }, { group: [:owners, :group_members] },
:invited_groups, :invited_groups,
:project_members, :project_members,
:project_feature :project_feature,
:route
] ]
}), }),
self.class.data_attribute self.class.data_attribute
......
...@@ -35,6 +35,19 @@ describe Issues::ReferencedMergeRequestsService do ...@@ -35,6 +35,19 @@ describe Issues::ReferencedMergeRequestsService do
expect(mrs).to eq([closing_mr, referencing_mr, closing_mr_other_project, referencing_mr_other_project]) expect(mrs).to eq([closing_mr, referencing_mr, closing_mr_other_project, referencing_mr_other_project])
expect(closed_by_mrs).to eq([closing_mr, closing_mr_other_project]) expect(closed_by_mrs).to eq([closing_mr, closing_mr_other_project])
end end
context 'performance' do
it 'does not run extra queries when extra namespaces are included', :use_clean_rails_memory_store_caching do
service.execute(issue) # warm cache
control_count = ActiveRecord::QueryRecorder.new { service.execute(issue) }.count
third_project = create(:project, :public)
create_closing_mr(source_project: third_project)
service.execute(issue) # warm cache
expect { service.execute(issue) }.not_to exceed_query_limit(control_count)
end
end
end end
describe '#referenced_merge_requests' do describe '#referenced_merge_requests' 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