diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb')
-rw-r--r-- | lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb b/lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb index 29a2d55df1a..c9a75b39959 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb @@ -22,6 +22,29 @@ module Gitlab stage.start_event.timestamp_projection ) end + + # rubocop: disable CodeReuse/ActiveRecord + def order_by_end_event(query) + ordered_query = query.reorder(stage.end_event.timestamp_projection.desc) + + # When filtering for more than one label, postgres requires the columns in ORDER BY to be present in the GROUP BY clause + if requires_grouping? + column_list = [ + ordered_query.arel_table[:id], + *stage.end_event.column_list, + *stage.start_event.column_list + ] + + ordered_query = ordered_query.group(column_list) + end + + ordered_query + end + # rubocop: enable CodeReuse/ActiveRecord + + def requires_grouping? + Array(params[:label_name]).size > 1 + end end end end |