Commit 3d6e073f authored by Stan Hu's avatar Stan Hu

Merge branch 'mc/backstage/nplus-one-artifacts-pipelines-show' into 'master'

Preload job_artifacts when loading builds in stage

Closes #38306

See merge request gitlab-org/gitlab!21307
parents 13406da8 d7e2a7f6
......@@ -15,9 +15,10 @@ module Ci
private
def preload_statuses(statuses)
loaded_statuses = statuses.load
statuses.tap do |statuses|
# rubocop: disable CodeReuse/ActiveRecord
ActiveRecord::Associations::Preloader.new.preload(preloadable_statuses(statuses), :tags)
ActiveRecord::Associations::Preloader.new.preload(preloadable_statuses(loaded_statuses), %w[tags job_artifacts_archive metadata])
# rubocop: enable CodeReuse/ActiveRecord
end
end
......
......@@ -6,8 +6,8 @@ describe Ci::LegacyStagePresenter do
let(:legacy_stage) { create(:ci_stage) }
let(:presenter) { described_class.new(legacy_stage) }
let!(:build) { create(:ci_build, :tags, pipeline: legacy_stage.pipeline, stage: legacy_stage.name) }
let!(:retried_build) { create(:ci_build, :tags, :retried, pipeline: legacy_stage.pipeline, stage: legacy_stage.name) }
let!(:build) { create(:ci_build, :tags, :artifacts, pipeline: legacy_stage.pipeline, stage: legacy_stage.name) }
let!(:retried_build) { create(:ci_build, :tags, :artifacts, :retried, pipeline: legacy_stage.pipeline, stage: legacy_stage.name) }
before do
create(:generic_commit_status, pipeline: legacy_stage.pipeline, stage: legacy_stage.name)
......@@ -19,6 +19,14 @@ describe Ci::LegacyStagePresenter do
it 'preloads build tags' do
expect(latest_ordered_statuses.second.association(:tags)).to be_loaded
end
it 'preloads build artifacts archive' do
expect(latest_ordered_statuses.second.association(:job_artifacts_archive)).to be_loaded
end
it 'preloads build artifacts metadata' do
expect(latest_ordered_statuses.second.association(:metadata)).to be_loaded
end
end
describe '#retried_ordered_statuses' do
......@@ -27,5 +35,13 @@ describe Ci::LegacyStagePresenter do
it 'preloads build tags' do
expect(retried_ordered_statuses.first.association(:tags)).to be_loaded
end
it 'preloads build artifacts archive' do
expect(retried_ordered_statuses.first.association(:job_artifacts_archive)).to be_loaded
end
it 'preloads build artifacts metadata' do
expect(retried_ordered_statuses.first.association(:metadata)).to be_loaded
end
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