diff options
author | Mike Greiling <mike@pixelcog.com> | 2018-11-07 05:21:25 +0000 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2018-11-07 05:21:25 +0000 |
commit | 839a654ef0da5f13729074e24231344fe64a2cdc (patch) | |
tree | 6dff019a9ea6164af7c9721ca2cb2ba30b886002 /app/models/ci/pipeline.rb | |
parent | 0a4eeafb43236359c55e221bdc8cab52acef9a0f (diff) | |
parent | cf8fe12b7b3a24082db47f71c80b01e62e391f32 (diff) | |
download | gitlab-ce-gl-ui-loading-icon.tar.gz |
Merge branch 'master' into 'gl-ui-loading-icon'gl-ui-loading-icon
# Conflicts:
# app/assets/javascripts/jobs/components/job_app.vue
Diffstat (limited to 'app/models/ci/pipeline.rb')
-rw-r--r-- | app/models/ci/pipeline.rb | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index aeee7f0a5d2..56010e899a4 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -181,22 +181,31 @@ module Ci # # ref - The name (or names) of the branch(es)/tag(s) to limit the list of # pipelines to. - def self.newest_first(ref = nil) + # limit - This limits a backlog search, default to 100. + def self.newest_first(ref: nil, limit: 100) relation = order(id: :desc) + relation = relation.where(ref: ref) if ref + + if limit + ids = relation.limit(limit).select(:id) + # MySQL does not support limit in subquery + ids = ids.pluck(:id) if Gitlab::Database.mysql? + relation = relation.where(id: ids) + end - ref ? relation.where(ref: ref) : relation + relation end def self.latest_status(ref = nil) - newest_first(ref).pluck(:status).first + newest_first(ref: ref).pluck(:status).first end def self.latest_successful_for(ref) - newest_first(ref).success.take + newest_first(ref: ref).success.take end def self.latest_successful_for_refs(refs) - relation = newest_first(refs).success + relation = newest_first(ref: refs).success relation.each_with_object({}) do |pipeline, hash| hash[pipeline.ref] ||= pipeline @@ -238,6 +247,10 @@ module Ci end end + def self.latest_successful_ids_per_project + success.group(:project_id).select('max(id) as id') + end + def self.truncate_sha(sha) sha[0...8] end |