summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-12-15 18:38:26 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-12-15 18:38:26 +0800
commitb4a7e7cfbf2a79cf6ecdb8b251ad41c09a40e5bd (patch)
treebd2be369ed6cbbd74cabf408c436cc146e40de67
parentcc6f578d5fc45f9c3d4cc7df5af72b15ce47b3a8 (diff)
downloadgitlab-ce-b4a7e7cfbf2a79cf6ecdb8b251ad41c09a40e5bd.tar.gz
Don't call anything on a block, use simple if
Feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7333#note_20058743
-rw-r--r--app/models/ci/pipeline.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 9edfc75eac7..48354cdbefb 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -89,13 +89,15 @@ module Ci
# ref can't be HEAD or SHA, can only be branch/tag name
scope :latest, ->(ref = nil) do
- max_id = unscope(:select).select("max(#{quoted_table_name}.id)")
+ max_id = unscope(:select)
+ .select("max(#{quoted_table_name}.id)")
+ .group(:ref, :sha)
if ref
- where(ref: ref)
+ where(id: max_id, ref: ref)
else
- self
- end.where(id: max_id.group(:ref, :sha))
+ where(id: max_id)
+ end
end
def self.latest_status(ref = nil)