summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-09-06 19:36:07 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-09-06 19:36:07 +0800
commit7351c269deae2c28c63e793df11155e0f6c75d04 (patch)
tree6777f0040d8dbc57ad6fbe01197791b0e284027e
parent3a68c98973c2c17e0c6e57184c4b2605a2dd274e (diff)
downloadgitlab-ce-7351c269deae2c28c63e793df11155e0f6c75d04.tar.gz
Sort by database, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6084#note_14991226 and https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6084#note_14994233
-rw-r--r--lib/gitlab/ci/pipeline_duration.rb6
-rw-r--r--spec/lib/gitlab/ci/pipeline_duration_spec.rb2
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/gitlab/ci/pipeline_duration.rb b/lib/gitlab/ci/pipeline_duration.rb
index 0333807263f..711f911346c 100644
--- a/lib/gitlab/ci/pipeline_duration.rb
+++ b/lib/gitlab/ci/pipeline_duration.rb
@@ -88,7 +88,8 @@ module Gitlab
def from_pipeline(pipeline)
status = %w[success failed running canceled]
- builds = pipeline.builds.latest.where(status: status)
+ builds = pipeline.builds.latest.
+ where(status: status).where.not(started_at: nil).order(:started_at)
from_builds(builds, :started_at, :finished_at)
end
@@ -101,8 +102,9 @@ module Gitlab
from_periods(periods)
end
+ # periods should be sorted by `first`
def from_periods(periods)
- process_duration(process_periods(periods.sort_by(&:first)))
+ process_duration(process_periods(periods))
end
private
diff --git a/spec/lib/gitlab/ci/pipeline_duration_spec.rb b/spec/lib/gitlab/ci/pipeline_duration_spec.rb
index 580af97bea7..b26728a843c 100644
--- a/spec/lib/gitlab/ci/pipeline_duration_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline_duration_spec.rb
@@ -110,6 +110,6 @@ describe Gitlab::Ci::PipelineDuration do
Gitlab::Ci::PipelineDuration::Period.new(first, last)
end
- Gitlab::Ci::PipelineDuration.from_periods(periods)
+ Gitlab::Ci::PipelineDuration.from_periods(periods.sort_by(&:first))
end
end