diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /app/models/ci/pipeline.rb | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'app/models/ci/pipeline.rb')
-rw-r--r-- | app/models/ci/pipeline.rb | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 5d079f57267..70e67953e31 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true module Ci - class Pipeline < ApplicationRecord - extend Gitlab::Ci::Model + class Pipeline < Ci::ApplicationRecord include Ci::HasStatus include Importable include AfterCommitQueue @@ -319,6 +318,7 @@ module Ci scope :created_before_id, -> (id) { where('ci_pipelines.id < ?', id) } scope :before_pipeline, -> (pipeline) { created_before_id(pipeline.id).outside_pipeline_family(pipeline) } scope :eager_load_project, -> { eager_load(project: [:route, { namespace: :route }]) } + scope :with_pipeline_source, -> (source) { where(source: source)} scope :outside_pipeline_family, ->(pipeline) do where.not(id: pipeline.same_family_pipeline_ids) @@ -378,11 +378,15 @@ module Ci end def self.latest_successful_for_refs(refs) - relation = newest_first(ref: refs).success + return Ci::Pipeline.none if refs.empty? - relation.each_with_object({}) do |pipeline, hash| - hash[pipeline.ref] ||= pipeline - end + refs_values = refs.map { |ref| "(#{connection.quote(ref)})" }.join(",") + join_query = success.where("refs_values.ref = ci_pipelines.ref").order(id: :desc).limit(1) + + Ci::Pipeline + .from("(VALUES #{refs_values}) refs_values (ref)") + .joins("INNER JOIN LATERAL (#{join_query.to_sql}) #{Ci::Pipeline.table_name} ON TRUE") + .index_by(&:ref) end def self.latest_running_for_ref(ref) @@ -393,6 +397,10 @@ module Ci newest_first(ref: ref).failed.take end + def self.jobs_count_in_alive_pipelines + created_after(24.hours.ago).alive.joins(:builds).count + end + # Returns a Hash containing the latest pipeline for every given # commit. # |