Don't call anything on a block, use simple if

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7333#note_20058743
This commit is contained in:
Lin Jen-Shin 2016-12-15 18:38:26 +08:00
parent cc6f578d5f
commit b4a7e7cfbf
1 changed files with 6 additions and 4 deletions

View File

@ -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)