diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-04-24 11:18:12 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-04-24 11:24:43 +0200 |
commit | 5771972e8ca2a7ad06445ee539054b23cf228de8 (patch) | |
tree | 17f753f9cef764748068c521dcf9fa22d2b107e8 /app/models/ci/stage.rb | |
parent | fc6ec8adab6e3bcfc9163bd003d77a8fc14fe107 (diff) | |
download | gitlab-ce-5771972e8ca2a7ad06445ee539054b23cf228de8.tar.gz |
Use database query to calculate average stage position
Diffstat (limited to 'app/models/ci/stage.rb')
-rw-r--r-- | app/models/ci/stage.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index a80c72d3452..5a77a909b9d 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -24,12 +24,14 @@ module Ci self.status = DEFAULT_STATUS if self.status.nil? end - before_validation do - next unless index.nil? + before_validation unless: :importing? do + next if index.present? - statuses.pluck(:stage_idx).tap do |indices| - self.index = indices.max_by { |index| indices.count(index) } - end + self.index = statuses.select(:stage_idx) + .where('stage_idx IS NOT NULL') + .group(:stage_idx) + .order('COUNT(*) DESC') + .first&.stage_idx.to_i end state_machine :status, initial: :created do |