Commit b8376928 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'ab-fix-bad-preloads' into 'master'

Fix preloading unrelated associations for CommitStatus

See merge request gitlab-org/gitlab!67439
parents 25d58154 1bcd7c0e
......@@ -2,6 +2,9 @@
module Ci
class DropPipelineService
PRELOADED_COMMIT_STATUS_RELATIONS = [:project, :pipeline].freeze
PRELOADED_CI_BUILD_RELATIONS = [:metadata, :deployment, :taggings].freeze
# execute service asynchronously for each cancelable pipeline
def execute_async_for_all(pipelines, failure_reason, context_user)
pipelines.cancelable.select(:id).find_in_batches do |pipelines_batch|
......@@ -27,11 +30,11 @@ module Ci
private
def preload_associations_for_drop(builds_batch)
ActiveRecord::Associations::Preloader.new.preload( # rubocop: disable CodeReuse/ActiveRecord
builds_batch,
[:project, :pipeline, :metadata, :deployment, :taggings]
)
# rubocop: disable CodeReuse/ActiveRecord
def preload_associations_for_drop(commit_status_batch)
ActiveRecord::Associations::Preloader.new.preload(commit_status_batch, PRELOADED_COMMIT_STATUS_RELATIONS)
ActiveRecord::Associations::Preloader.new.preload(commit_status_batch.select { |job| job.is_a?(Ci::Build) }, PRELOADED_CI_BUILD_RELATIONS)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -9,8 +9,10 @@ RSpec.describe Ci::DropPipelineService do
let!(:cancelable_pipeline) { create(:ci_pipeline, :running, user: user) }
let!(:running_build) { create(:ci_build, :running, pipeline: cancelable_pipeline) }
let!(:commit_status_running) { create(:commit_status, :running, pipeline: cancelable_pipeline) }
let!(:success_pipeline) { create(:ci_pipeline, :success, user: user) }
let!(:success_build) { create(:ci_build, :success, pipeline: success_pipeline) }
let!(:commit_status_success) { create(:commit_status, :success, pipeline: cancelable_pipeline) }
describe '#execute_async_for_all' do
subject { described_class.new.execute_async_for_all(user.pipelines, failure_reason, user) }
......
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