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
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
......
......@@ -36,6 +36,5 @@
.table-holder
%table.table.builds
- stages = ci_commit.statuses.latest.stages_status
- stages.each do |stage, status|
= render 'ci_stage', stage: stage, status: status
- ci_commit.statuses.stages.each do |stage|
= render 'projects/commit/ci_stage', stage: stage, statuses: ci_commit.statuses.where(stage: stage)
- statuses = ci_commit.statuses.where(stage: stage).to_a
- retried = statuses.select(&:retried?)
- latest = statuses - retried
- latest = statuses.latest
- retried = statuses.where.not(id: latest)
%tr
%th{colspan: 10}
%strong
- status = latest.status
%span{class: "ci-status-link ci-status-icon-#{status}"}
= ci_icon_for_status(status)
&nbsp;
= stage.titleize.pluralize
= render latest, 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 latest.ordered, coverage: @project.build_coverage_enabled?, tage: false, ref: false, allow_retry: true
= render retried.ordered, coverage: @project.build_coverage_enabled?, stage: false, ref: false, retried: true
%tr
%td{colspan: 10}
&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