Commit d38fb942 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Optimize Ci::Pipeline.latest query

Since we already know which ref we want, we could filter it out first.

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/issues/26570#note_23423376

Closes #26570
parent 12cd4c83
......@@ -91,6 +91,7 @@ module Ci
scope :latest, ->(ref = nil) do
max_id = unscope(:select)
.select("max(#{quoted_table_name}.id)")
.where(ref: ref)
.group(:ref, :sha)
relation = ref ? where(ref: ref) : self
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment