diff options
author | Stan Hu <stanhu@gmail.com> | 2018-06-03 14:36:22 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-06-05 02:47:16 +0300 |
commit | 2bb94ff7f915bdc09275085a075e202f92241811 (patch) | |
tree | 7a7b5c8269e02c7097b4bc3a881f41cee53fab82 /spec/requests | |
parent | c26cbfcdfb6a0c83253f42be016692abc3548e8c (diff) |
Eliminate N+1 queries for CI job artifacts in /api/projects/:id/pipelines/:pipeline_id/jobs
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/jobs_spec.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/spec/requests/api/jobs_spec.rb b/spec/requests/api/jobs_spec.rb index 45082e644ca..50d6f4b4d99 100644 --- a/spec/requests/api/jobs_spec.rb +++ b/spec/requests/api/jobs_spec.rb @@ -177,6 +177,18 @@ describe API::Jobs do json_response.each { |job| expect(job['pipeline']['id']).to eq(pipeline.id) } end end + + it 'avoids N+1 queries' do + control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do + get api("/projects/#{project.id}/pipelines/#{pipeline.id}/jobs", api_user), query + end.count + + 3.times { create(:ci_build, :artifacts, pipeline: pipeline) } + + expect do + get api("/projects/#{project.id}/pipelines/#{pipeline.id}/jobs", api_user), query + end.not_to exceed_all_query_limit(control_count) + end end context 'unauthorized user' do |