From a763dec903469147e4b8b72c9398a8f43e83b488 Mon Sep 17 00:00:00 2001 From: Mehmet Emin INAC <minac@gitlab.com> Date: Fri, 8 Jan 2021 14:11:53 +0100 Subject: [PATCH] Add test for N+1 queries --- .../populate_finding_uuid_for_vulnerability_feedback_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/lib/gitlab/background_migration/populate_finding_uuid_for_vulnerability_feedback_spec.rb b/spec/lib/gitlab/background_migration/populate_finding_uuid_for_vulnerability_feedback_spec.rb index 14464c338e1..12cadabf8cd 100644 --- a/spec/lib/gitlab/background_migration/populate_finding_uuid_for_vulnerability_feedback_spec.rb +++ b/spec/lib/gitlab/background_migration/populate_finding_uuid_for_vulnerability_feedback_spec.rb @@ -86,5 +86,10 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateFindingUuidForVulnerabilityF expect(Gitlab::BackgroundMigration::Logger).to have_received(:info).once end + + it 'preloads the finding and identifier records to prevent N+1 queries' do + # Load feedback records(1), load findings(2), load identifiers(3) and finally update feedback records one by one(6) + expect { populate_finding_uuids }.not_to exceed_query_limit(6) + end end end -- 2.30.9