diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-14 11:12:27 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-14 11:12:27 +0300 |
commit | 3772445de3063dda5e5fb2f21b6debf14032cc92 (patch) | |
tree | 8db2e49b644638f160392062221e6a0a56fcfd62 /app/presenters | |
parent | 28a9333b4b418ce3f96fcd0a530d76ac86e6c4ed (diff) |
Add latest changes from gitlab-org/gitlab@13-11-stable-ee
Diffstat (limited to 'app/presenters')
-rw-r--r-- | app/presenters/ci/stage_presenter.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/app/presenters/ci/stage_presenter.rb b/app/presenters/ci/stage_presenter.rb new file mode 100644 index 00000000000..9ec3f8d153a --- /dev/null +++ b/app/presenters/ci/stage_presenter.rb @@ -0,0 +1,32 @@ +# 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) + loaded_statuses = statuses.load + statuses.tap do |statuses| + # rubocop: disable CodeReuse/ActiveRecord + ActiveRecord::Associations::Preloader.new.preload(preloadable_statuses(loaded_statuses), %w[pipeline tags job_artifacts_archive metadata]) + # rubocop: enable CodeReuse/ActiveRecord + end + end + + def preloadable_statuses(statuses) + statuses.reject do |status| + status.instance_of?(::GenericCommitStatus) || status.instance_of?(::Ci::Bridge) + end + end + end +end |