summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-04-19 12:51:51 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2018-04-19 12:51:51 +0000
commita313aeceeeb20802ff9311199c839380414a588f (patch)
treeff45c2b9783a28fac95363b729f9d38e7e77acf4 /spec/models
parent9cc011fdedab44f7423ed24150c93117abc689aa (diff)
parent775211bc7076bba14d6e268fb324391124a2751f (diff)
downloadgitlab-ce-a313aeceeeb20802ff9311199c839380414a588f.tar.gz
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
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/note_spec.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 86962cd8d61..6a6c71e6c82 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -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