diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /lib/gitlab/analytics/cycle_analytics/aggregated/records_fetcher.rb | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) | |
download | gitlab-ce-a7b3560714b4d9cc4ab32dffcd1f74a284b93580.tar.gz |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'lib/gitlab/analytics/cycle_analytics/aggregated/records_fetcher.rb')
-rw-r--r-- | lib/gitlab/analytics/cycle_analytics/aggregated/records_fetcher.rb | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/lib/gitlab/analytics/cycle_analytics/aggregated/records_fetcher.rb b/lib/gitlab/analytics/cycle_analytics/aggregated/records_fetcher.rb index 1742d396c10..55e421173d7 100644 --- a/lib/gitlab/analytics/cycle_analytics/aggregated/records_fetcher.rb +++ b/lib/gitlab/analytics/cycle_analytics/aggregated/records_fetcher.rb @@ -36,7 +36,13 @@ module Gitlab def serialized_records strong_memoize(:serialized_records) do - records = ordered_and_limited_query.select(stage_event_model.arel_table[Arel.star], duration_in_seconds.as('total_time')) + # When RecordsFetcher is used with query sourced from + # InOperatorOptimization::QueryBuilder only columns + # used in ORDER BY statement would be selected by Arel.start operation + selections = [stage_event_model.arel_table[Arel.star]] + selections << duration_in_seconds.as('total_time') if params[:sort] != :duration # duration sorting already exposes this data + + records = limited_query.select(*selections) yield records if block_given? issuables_and_records = load_issuables(records) @@ -56,27 +62,12 @@ module Gitlab end end - # rubocop: disable CodeReuse/ActiveRecord - def ordered_and_limited_query - sorting_options = { - end_event: { - asc: -> { query.order(end_event_timestamp: :asc) }, - desc: -> { query.order(end_event_timestamp: :desc) } - }, - duration: { - asc: -> { query.order(duration.asc) }, - desc: -> { query.order(duration.desc) } - } - } - - sort_lambda = sorting_options.dig(sort, direction) || sorting_options.dig(:end_event, :desc) - - sort_lambda.call + def limited_query + query .page(page) .per(per_page) .without_count end - # rubocop: enable CodeReuse/ActiveRecord private |