summaryrefslogtreecommitdiff
path: root/app/models/ci/pipeline.rb
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-12-23 16:53:56 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-12-23 17:03:01 +0800
commitb63f2794f076a7394c8a000829a632bcffef2b00 (patch)
treea6094250a08326556d3f767a1f6c3af527292971 /app/models/ci/pipeline.rb
parent358a2d8b0dac1ca7d82c10103d2dca4b73b412ae (diff)
downloadgitlab-ce-b63f2794f076a7394c8a000829a632bcffef2b00.tar.gz
Ci::Pipeline.latest order by id DESC
The name latest implies that it's reverse chronological, and we did expect it that way. https://gitlab.com/gitlab-org/gitlab-ce/issues/25993#note_20429761 >>> ok, I think markglenfletchera is correct in https://gitlab.com/gitlab-com/support-forum/issues/1394#note_20399939 that `Project#latest_successful_builds_for` is giving oldest pipeline rather than latest pipeline. This is a ~regression introduced by !7333 where `order(id: :desc)` was removed causing this. The offending change was: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7333/diffs#b22732e5f39e176c7c719fe485847d0fb0564275_92_108 The confusion was caused by the `latest` name implication, which actually didn't order anything, and I think we should add `order(id: :desc)` to `Ci::Pipeline.latest` otherwise it's confusing that it's not actually ordered. >>> Closes #25993
Diffstat (limited to 'app/models/ci/pipeline.rb')
-rw-r--r--app/models/ci/pipeline.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index f2f6453b3b9..5494a8da0d9 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -93,11 +93,13 @@ module Ci
.select("max(#{quoted_table_name}.id)")
.group(:ref, :sha)
- if ref
- where(id: max_id, ref: ref)
- else
- where(id: max_id)
- end
+ query = if ref
+ where(id: max_id, ref: ref)
+ else
+ where(id: max_id)
+ end
+
+ query.order(id: :desc)
end
def self.latest_status(ref = nil)