From d38fb942e188021d7def5eb577a73c82b8e5e66d Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 16 Feb 2017 21:08:47 +0800 Subject: 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 --- app/models/ci/pipeline.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index dc4590a9923..2a987bfa87b 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -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 -- cgit v1.2.1