2021-05-05 15:10:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
class StagePresenter < Gitlab::View::Presenter::Delegated
|
|
|
|
presents :stage
|
|
|
|
|
|
|
|
def latest_ordered_statuses
|
|
|
|
preload_statuses(stage.statuses.latest_ordered)
|
|
|
|
end
|
|
|
|
|
|
|
|
def retried_ordered_statuses
|
|
|
|
preload_statuses(stage.statuses.retried_ordered)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def preload_statuses(statuses)
|
2021-08-31 09:08:57 +00:00
|
|
|
common_relations = [:pipeline]
|
2021-05-05 15:10:05 +00:00
|
|
|
|
2021-08-31 09:08:57 +00:00
|
|
|
preloaders = {
|
|
|
|
::Ci::Build => [:metadata, :tags, :job_artifacts_archive],
|
|
|
|
::Ci::Bridge => [:metadata, :downstream_pipeline],
|
|
|
|
::GenericCommitStatus => []
|
|
|
|
}
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
preloaders.each do |klass, relations|
|
|
|
|
ActiveRecord::Associations::Preloader
|
|
|
|
.new
|
|
|
|
.preload(statuses.select { |job| job.is_a?(klass) }, relations + common_relations)
|
2021-05-05 15:10:05 +00:00
|
|
|
end
|
2021-08-31 09:08:57 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
|
|
|
|
statuses
|
2021-05-05 15:10:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|