summaryrefslogtreecommitdiff
path: root/app/models/ci/pipeline.rb
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2018-11-06 13:15:38 +0000
committerGrzegorz Bizon <grzegorz@gitlab.com>2018-11-06 13:15:38 +0000
commit6e9179ab461c0100f3e870c655fa566a782e0f9a (patch)
tree946e628ccb580eff671ae7b9b4cd34c0aa665d27 /app/models/ci/pipeline.rb
parent1cf4aa023978cfb28e73058e66e7d16d864e6f5a (diff)
parent202df2fbbcbcaaf4e4136863256dc068d045178b (diff)
downloadgitlab-ce-6e9179ab461c0100f3e870c655fa566a782e0f9a.tar.gz
Merge branch 'support-project-security-dashboard' into 'master'
Backport support project security dashboard changes See merge request gitlab-org/gitlab-ce!22824
Diffstat (limited to 'app/models/ci/pipeline.rb')
-rw-r--r--app/models/ci/pipeline.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 0daf2419b67..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