Commit 504a1fac authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix SQL queries for calculating stages status

parent 7c1acb02
...@@ -51,7 +51,7 @@ class CommitStatus < ActiveRecord::Base ...@@ -51,7 +51,7 @@ class CommitStatus < ActiveRecord::Base
alias_attribute :author, :user alias_attribute :author, :user
scope :latest, -> { where(id: unscope(:select).select('max(id)').group(:name, :commit_id)) } 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]) } scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) }
state_machine :status, initial: :pending do state_machine :status, initial: :pending do
...@@ -91,13 +91,15 @@ class CommitStatus < ActiveRecord::Base ...@@ -91,13 +91,15 @@ class CommitStatus < ActiveRecord::Base
end end
def self.stages def self.stages
order_by = 'max(stage_idx)' # We group by stage name, but order stages by their's index
CommitStatus.where(id: all).group('stage').order(order_by).pluck(:stage, order_by).map(&:first).compact unscoped.from(all, :sg).group('stage').order('max(stage_idx)', 'stage').pluck('sg.stage')
end end
def self.stages_status def self.stages_status
all.stages.inject({}) do |h, stage| # We execute subquery for each of the stages which calculates an Stage Status
h[stage] = all.where(stage: 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 h
end end
end end
......
...@@ -36,6 +36,5 @@ ...@@ -36,6 +36,5 @@
.table-holder .table-holder
%table.table.builds %table.table.builds
- stages = ci_commit.statuses.latest.stages_status - ci_commit.statuses.stages.each do |stage|
- stages.each do |stage, status| = render 'projects/commit/ci_stage', stage: stage, statuses: ci_commit.statuses.where(stage: stage)
= render 'ci_stage', stage: stage, status: status
- statuses = ci_commit.statuses.where(stage: stage).to_a - latest = statuses.latest
- retried = statuses.select(&:retried?) - retried = statuses.where.not(id: latest)
- latest = statuses - retried
%tr %tr
%th{colspan: 10} %th{colspan: 10}
%strong %strong
- status = latest.status
%span{class: "ci-status-link ci-status-icon-#{status}"} %span{class: "ci-status-link ci-status-icon-#{status}"}
= ci_icon_for_status(status) = ci_icon_for_status(status)
&nbsp; &nbsp;
= stage.titleize.pluralize = stage.titleize.pluralize
= render latest, coverage: @project.build_coverage_enabled?, tage: false, ref: false, allow_retry: true = render latest.ordered, coverage: @project.build_coverage_enabled?, tage: false, ref: false, allow_retry: true
= render retried, coverage: @project.build_coverage_enabled?, stage: false, ref: false, retried: true = render retried.ordered, coverage: @project.build_coverage_enabled?, stage: false, ref: false, retried: true
%tr %tr
%td{colspan: 10} %td{colspan: 10}
&nbsp; &nbsp;
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