diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-05-10 00:58:53 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-05-10 00:58:53 +0300 |
commit | 504a1fac95a2af2cf90f00f310d244d8d37f0015 (patch) | |
tree | a87685c6e8ffa40ec7621b0a66cb082aaadfc009 /app/models | |
parent | 7c1acb022a215743caa57fde3bb3459b35aaf01d (diff) | |
download | gitlab-ce-504a1fac95a2af2cf90f00f310d244d8d37f0015.tar.gz |
Fix SQL queries for calculating stages status
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/commit_status.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index b031259e252..0c0c3d38f94 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -51,7 +51,7 @@ class CommitStatus < ActiveRecord::Base alias_attribute :author, :user scope :latest, -> { where(id: unscope(:select).select('max(id)').group(:name, :commit_id)) } - scope :ordered, -> { order(:ref, :stage_idx, :name) } + scope :ordered, -> { order(:name) } scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) } state_machine :status, initial: :pending do @@ -91,13 +91,15 @@ class CommitStatus < ActiveRecord::Base end def self.stages - order_by = 'max(stage_idx)' - CommitStatus.where(id: all).group('stage').order(order_by).pluck(:stage, order_by).map(&:first).compact + # We group by stage name, but order stages by their's index + unscoped.from(all, :sg).group('stage').order('max(stage_idx)', 'stage').pluck('sg.stage') end def self.stages_status - all.stages.inject({}) do |h, stage| - h[stage] = all.where(stage: stage).status + # We execute subquery for each of the stages which calculates an Stage Status + statuses = unscoped.from(all, :sg).group('stage').pluck('sg.stage', all.where('stage=sg.stage').status_sql) + statuses.inject({}) do |h, k| + h[k.first] = k.last h end end |