Commit d6f6602c authored by Matija Čupić's avatar Matija Čupić

Make preloading tags final step in relation

parent eacf54fe
...@@ -4,16 +4,24 @@ module Ci ...@@ -4,16 +4,24 @@ module Ci
class LegacyStagePresenter < Gitlab::View::Presenter::Delegated class LegacyStagePresenter < Gitlab::View::Presenter::Delegated
presents :legacy_stage presents :legacy_stage
def preloaded_statuses def latest_ordered_statuses
legacy_stage.statuses.tap do |statuses| preload_statuses(legacy_stage.statuses.latest_ordered)
end
def retried_ordered_statuses
preload_statuses(legacy_stage.statuses.retried_ordered)
end
private
def preload_statuses(statuses)
statuses.tap do |statuses|
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
ActiveRecord::Associations::Preloader.new.preload(preloadable_statuses(statuses), :tags) ActiveRecord::Associations::Preloader.new.preload(preloadable_statuses(statuses), :tags)
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
end end
end end
private
def preloadable_statuses(statuses) def preloadable_statuses(statuses)
statuses.reject do |status| statuses.reject do |status|
status.instance_of?(::GenericCommitStatus) || status.instance_of?(::Ci::Bridge) status.instance_of?(::GenericCommitStatus) || status.instance_of?(::Ci::Bridge)
......
- statuses = stage.present(current_user: current_user).preloaded_statuses - stage = stage.present(current_user: current_user)
%tr %tr
%th{ colspan: 10 } %th{ colspan: 10 }
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
= ci_icon_for_status(stage.status) = ci_icon_for_status(stage.status)
&nbsp; &nbsp;
= stage.name.titleize = stage.name.titleize
= render statuses.latest_ordered, stage: false, ref: false, pipeline_link: false, allow_retry: true = render stage.latest_ordered_statuses, stage: false, ref: false, pipeline_link: false, allow_retry: true
= render statuses.retried_ordered, stage: false, ref: false, pipeline_link: false, retried: true = render stage.retried_ordered_statuses, stage: false, ref: false, pipeline_link: false, retried: true
%tr %tr
%td{ colspan: 10 } %td{ colspan: 10 }
&nbsp; &nbsp;
...@@ -4,18 +4,28 @@ require 'spec_helper' ...@@ -4,18 +4,28 @@ require 'spec_helper'
describe Ci::LegacyStagePresenter do describe Ci::LegacyStagePresenter do
let(:legacy_stage) { create(:ci_stage) } let(:legacy_stage) { create(:ci_stage) }
let(:presenter) { described_class.new(legacy_stage) }
describe '#preloaded_statuses' do let!(:build) { create(:ci_build, :tags, pipeline: legacy_stage.pipeline, stage: legacy_stage.name) }
subject(:preloaded_statuses) { described_class.new(legacy_stage).preloaded_statuses } let!(:retried_build) { create(:ci_build, :tags, :retried, pipeline: legacy_stage.pipeline, stage: legacy_stage.name) }
let!(:build) { create(:ci_build, :tags, pipeline: legacy_stage.pipeline, stage: legacy_stage.name) } before do
create(:generic_commit_status, pipeline: legacy_stage.pipeline, stage: legacy_stage.name)
end
describe '#latest_ordered_statuses' do
subject(:latest_ordered_statuses) { presenter.latest_ordered_statuses }
before do it 'preloads build tags' do
create(:generic_commit_status, pipeline: legacy_stage.pipeline, stage: legacy_stage.name) expect(latest_ordered_statuses.second.association(:tags)).to be_loaded
end end
end
describe '#retried_ordered_statuses' do
subject(:retried_ordered_statuses) { presenter.retried_ordered_statuses }
it 'preloads build tags' do it 'preloads build tags' do
expect(preloaded_statuses.first.association(:tags)).to be_loaded expect(retried_ordered_statuses.first.association(:tags)).to be_loaded
end end
end 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