Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-08-16 15:23:02 +0300
committerSean McGivern <sean@gitlab.com>2018-08-21 14:45:05 +0300
commitfd072f7df71257e694a1d82525c4237ed9cef927 (patch)
treed3973ceb80fac6aac4369c608957ca2698a2a1e8 /spec/services/issues
parent2017c5c62abde0d6f24e3afc120365ee1aaaca4b (diff)
Fix CI pipelines N+1 in Issues::ReferencedMergeRequestsService
Whether the preloading belongs in the service or the controller is arguable, here. As the service is only used for one controller action, it seems reasonable to put it in the service, but that is not a definitive answer. Adding the preloads for MR project routes here doesn't seem to work, perhaps because of https://github.com/rails/rails/issues/32140.
Diffstat (limited to 'spec/services/issues')
-rw-r--r--spec/services/issues/referenced_merge_requests_service_spec.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/services/issues/referenced_merge_requests_service_spec.rb b/spec/services/issues/referenced_merge_requests_service_spec.rb
index 3349b97e688..d57bcf55af1 100644
--- a/spec/services/issues/referenced_merge_requests_service_spec.rb
+++ b/spec/services/issues/referenced_merge_requests_service_spec.rb
@@ -47,6 +47,24 @@ describe Issues::ReferencedMergeRequestsService do
expect { service.execute(issue) }.not_to exceed_query_limit(control_count)
end
+
+ it 'preloads the head pipeline for each merge request, and its routes' do
+ # Hack to ensure no data is preserved on issue before starting the spec,
+ # to avoid false negatives
+ reloaded_issue = Issue.find(issue.id)
+
+ pipeline_routes = lambda do |merge_requests|
+ merge_requests.map { |mr| mr.head_pipeline&.project&.full_path }
+ end
+
+ closing_mr_other_project.update!(head_pipeline: create(:ci_pipeline))
+ control_count = ActiveRecord::QueryRecorder.new { service.execute(reloaded_issue).each(&pipeline_routes) }
+
+ closing_mr.update!(head_pipeline: create(:ci_pipeline))
+
+ expect { service.execute(issue).each(&pipeline_routes) }
+ .not_to exceed_query_limit(control_count)
+ end
end
end