Commit 30d63816 authored by Adam Hegyi's avatar Adam Hegyi Committed by Nikola Milojevic

Use EXTRACT(EPOCH) when calculating durations

parent 1d835b16
...@@ -17,7 +17,7 @@ module Gitlab ...@@ -17,7 +17,7 @@ module Gitlab
def average_by_day def average_by_day
@query @query
.group(date_expression) .group(date_expression)
.select(date_expression.as('date'), duration.average.as('average_duration_in_seconds')) .select(date_expression.as('date'), duration_in_seconds.average.as('average_duration_in_seconds'))
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def seconds def seconds
@query = @query.select(median_duration_in_seconds.as('median')).reorder(nil) @query = @query.select(duration_in_seconds(percentile_cont).as('median')).reorder(nil)
result = @query.take || {} result = @query.take || {}
result['median'] || nil result['median'] || nil
......
...@@ -36,7 +36,7 @@ module Gitlab ...@@ -36,7 +36,7 @@ module Gitlab
def serialized_records def serialized_records
strong_memoize(:serialized_records) do strong_memoize(:serialized_records) do
records = ordered_and_limited_query.select(stage_event_model.arel_table[Arel.star], duration.as('total_time')) records = ordered_and_limited_query.select(stage_event_model.arel_table[Arel.star], duration_in_seconds.as('total_time'))
yield records if block_given? yield records if block_given?
issuables_and_records = load_issuables(records) issuables_and_records = load_issuables(records)
......
...@@ -27,13 +27,13 @@ module Gitlab ...@@ -27,13 +27,13 @@ module Gitlab
end end
end end
def median_duration_in_seconds
Arel::Nodes::Extract.new(percentile_cont, :epoch)
end
def in_progress? def in_progress?
params[:end_event_filter] == :in_progress params[:end_event_filter] == :in_progress
end end
def duration_in_seconds(duration_expression = duration)
Arel::Nodes::Extract.new(duration_expression, :epoch)
end
end end
end end
end end
......
...@@ -41,6 +41,19 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Aggregated::RecordsFetcher do ...@@ -41,6 +41,19 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Aggregated::RecordsFetcher do
it_behaves_like 'match returned records' it_behaves_like 'match returned records'
end end
context 'when intervalstyle setting is configured to "postgres"' do
it 'avoids nil durations' do
# ActiveRecord cannot parse the 'postgres' intervalstyle, it returns nil
# The setting is rolled back after the test case.
Analytics::CycleAnalytics::IssueStageEvent.connection.execute("SET LOCAL intervalstyle='postgres'")
records_fetcher.serialized_records do |relation|
durations = relation.map(&:total_time)
expect(durations).to all(be > 0)
end
end
end
context 'when sorting by end event ASC' do context 'when sorting by end event ASC' do
let(:expected_issue_ids) { [issue_2.iid, issue_1.iid, issue_3.iid] } let(:expected_issue_ids) { [issue_2.iid, issue_1.iid, issue_3.iid] }
......
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