diff options
author | Rémy Coutable <remy@rymai.me> | 2018-06-07 19:25:06 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-06-07 19:25:06 +0300 |
commit | 5024c4aacc9ff9fd9d069e9d6b87ebdfe2ef356e (patch) | |
tree | f98345e6545427c2f130b70183ea12e835bbc96e /spec | |
parent | 4e18206f84ac6a8149b816c3a3cdd9a1b141d709 (diff) | |
parent | 0206476ae2a2d659fd0fb42338050253a9a91439 (diff) |
Merge branch 'n-plus-one-notification-recipients' into 'master'
Fix some N+1s when calculating notification recipients
Closes #45534
See merge request gitlab-org/gitlab-ce!19535
Diffstat (limited to 'spec')
-rw-r--r-- | spec/services/notification_recipient_service_spec.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/services/notification_recipient_service_spec.rb b/spec/services/notification_recipient_service_spec.rb new file mode 100644 index 00000000000..340d4585e0c --- /dev/null +++ b/spec/services/notification_recipient_service_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe NotificationRecipientService do + let(:service) { described_class } + let(:assignee) { create(:user) } + let(:project) { create(:project, :public) } + let(:other_projects) { create_list(:project, 5, :public) } + + describe '#build_new_note_recipients' do + let(:issue) { create(:issue, project: project, assignees: [assignee]) } + let(:note) { create(:note_on_issue, noteable: issue, project_id: issue.project_id) } + + def create_watcher + watcher = create(:user) + create(:notification_setting, project: project, user: watcher, level: :watch) + + other_projects.each do |other_project| + create(:notification_setting, project: other_project, user: watcher, level: :watch) + end + end + + it 'avoids N+1 queries' do + create_watcher + + service.build_new_note_recipients(note) + + control_count = ActiveRecord::QueryRecorder.new do + service.build_new_note_recipients(note) + end + + create_watcher + + expect { service.build_new_note_recipients(note) }.not_to exceed_query_limit(control_count) + end + end +end |