Commit 2464d2b2 authored by Marius Bobin's avatar Marius Bobin

Fix timeout error when loading pipelines by commit SHA for GraphQL

It was loading all the pipelines for a given project and tried to match
them from with the requested one from Ruby. This was causing database
statement timeouts for projects with lots of pipelines.
parent f95046ba
...@@ -31,7 +31,7 @@ module Resolvers ...@@ -31,7 +31,7 @@ module Resolvers
end end
else else
BatchLoader::GraphQL.for(sha).batch(key: project) do |shas, loader, args| BatchLoader::GraphQL.for(sha).batch(key: project) do |shas, loader, args|
finder = ::Ci::PipelinesFinder.new(project, current_user, shas: shas) finder = ::Ci::PipelinesFinder.new(project, current_user, sha: shas)
finder.execute.each { |pipeline| loader.call(pipeline.sha.to_s, pipeline) } finder.execute.each { |pipeline| loader.call(pipeline.sha.to_s, pipeline) }
end end
......
---
title: Fix loading pipelines by commit SHA for GraphQL
merge_request:
author:
type: fixed
...@@ -7,6 +7,7 @@ RSpec.describe Resolvers::ProjectPipelineResolver do ...@@ -7,6 +7,7 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project, iid: '1234', sha: 'sha') } let_it_be(:pipeline) { create(:ci_pipeline, project: project, iid: '1234', sha: 'sha') }
let_it_be(:other_project_pipeline) { create(:ci_pipeline, project: project, iid: '1235', sha: 'sha2') }
let_it_be(:other_pipeline) { create(:ci_pipeline) } let_it_be(:other_pipeline) { create(:ci_pipeline) }
let(:current_user) { create(:user) } let(:current_user) { create(:user) }
...@@ -23,6 +24,11 @@ RSpec.describe Resolvers::ProjectPipelineResolver do ...@@ -23,6 +24,11 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
end end
it 'resolves pipeline for the passed iid' do it 'resolves pipeline for the passed iid' do
expect(Ci::PipelinesFinder)
.to receive(:new)
.with(project, current_user, iids: ['1234'])
.and_call_original
result = batch_sync do result = batch_sync do
resolve_pipeline(project, { iid: '1234' }) resolve_pipeline(project, { iid: '1234' })
end end
...@@ -31,6 +37,11 @@ RSpec.describe Resolvers::ProjectPipelineResolver do ...@@ -31,6 +37,11 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
end end
it 'resolves pipeline for the passed sha' do it 'resolves pipeline for the passed sha' do
expect(Ci::PipelinesFinder)
.to receive(:new)
.with(project, current_user, sha: ['sha'])
.and_call_original
result = batch_sync do result = batch_sync do
resolve_pipeline(project, { sha: 'sha' }) resolve_pipeline(project, { sha: 'sha' })
end end
...@@ -39,8 +50,6 @@ RSpec.describe Resolvers::ProjectPipelineResolver do ...@@ -39,8 +50,6 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
end end
it 'keeps the queries under the threshold for iid' do it 'keeps the queries under the threshold for iid' do
create(:ci_pipeline, project: project, iid: '1235')
control = ActiveRecord::QueryRecorder.new do control = ActiveRecord::QueryRecorder.new do
batch_sync { resolve_pipeline(project, { iid: '1234' }) } batch_sync { resolve_pipeline(project, { iid: '1234' }) }
end end
...@@ -54,8 +63,6 @@ RSpec.describe Resolvers::ProjectPipelineResolver do ...@@ -54,8 +63,6 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
end end
it 'keeps the queries under the threshold for sha' do it 'keeps the queries under the threshold for sha' do
create(:ci_pipeline, project: project, sha: 'sha2')
control = ActiveRecord::QueryRecorder.new do control = ActiveRecord::QueryRecorder.new do
batch_sync { resolve_pipeline(project, { sha: 'sha' }) } batch_sync { resolve_pipeline(project, { sha: 'sha' }) }
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment