From a89fb014a3f520d44351489bca73a42f3d4d42e8 Mon Sep 17 00:00:00 2001 From: Olivier Gonzalez Date: Mon, 5 Nov 2018 18:56:52 -0500 Subject: Backport generic methods to CE Allow to fetch all pipelines for every projects in a group and its subgroups. Allow to fetch the latest pipeline id for each projects of a group and its subgroups. --- app/models/ci/pipeline.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/models/ci/pipeline.rb') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index aeee7f0a5d2..0daf2419b67 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -238,6 +238,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 -- cgit v1.2.1 From 202df2fbbcbcaaf4e4136863256dc068d045178b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Mon, 5 Nov 2018 23:52:15 +0100 Subject: Backport support project security dashboard changes --- app/models/ci/pipeline.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'app/models/ci/pipeline.rb') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index aeee7f0a5d2..26c708c784e 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 -- cgit v1.2.1