Merge branch 'sh-fix-award-emoji-nplus-one-participants' into 'master'
Fix N+1 queries when loading participants for a commit note Closes #45526 See merge request gitlab-org/gitlab-ce!18471
This commit is contained in:
commit
a313aeceee
3 changed files with 23 additions and 1 deletions
|
@ -248,7 +248,7 @@ class Commit
|
|||
end
|
||||
|
||||
def notes_with_associations
|
||||
notes.includes(:author)
|
||||
notes.includes(:author, :award_emoji)
|
||||
end
|
||||
|
||||
def merge_requests
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fix N+1 queries when loading participants for a commit note
|
||||
merge_request:
|
||||
author:
|
||||
type: performance
|
|
@ -91,6 +91,23 @@ describe Note do
|
|||
it "keeps the commit around" do
|
||||
expect(note.project.repository.kept_around?(commit.id)).to be_truthy
|
||||
end
|
||||
|
||||
it 'does not generate N+1 queries for participants', :request_store do
|
||||
def retrieve_participants
|
||||
commit.notes_with_associations.map(&:participants).to_a
|
||||
end
|
||||
|
||||
# Project authorization checks are cached, establish a baseline
|
||||
retrieve_participants
|
||||
|
||||
control_count = ActiveRecord::QueryRecorder.new do
|
||||
retrieve_participants
|
||||
end
|
||||
|
||||
create(:note_on_commit, project: note.project, note: 'another note', noteable_id: commit.id)
|
||||
|
||||
expect { retrieve_participants }.not_to exceed_query_limit(control_count)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'authorization' do
|
||||
|
|
Loading…
Reference in a new issue