debian-mirror-gitlab/lib/gitlab/analytics/cycle_analytics/sorting.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1 KiB
Ruby
Raw Normal View History

2021-04-17 20:07:23 +05:30
# frozen_string_literal: true
module Gitlab
module Analytics
module CycleAnalytics
class Sorting
2021-06-08 01:23:25 +05:30
include StageQueryHelpers
def initialize(stage:, query:, params: {})
@stage = stage
@query = query
@params = params
end
2021-04-17 20:07:23 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2021-06-08 01:23:25 +05:30
def apply(sort, direction)
sorting_options = {
end_event: {
asc: -> { query.reorder(end_event_timestamp_projection.asc) },
desc: -> { query.reorder(end_event_timestamp_projection.desc) }
},
duration: {
asc: -> { query.reorder(duration.asc) },
desc: -> { query.reorder(duration.desc) }
}
}
2021-04-17 20:07:23 +05:30
2021-06-08 01:23:25 +05:30
sort_lambda = sorting_options.dig(sort, direction) || sorting_options.dig(:end_event, :desc)
sort_lambda.call
2021-04-17 20:07:23 +05:30
end
2021-06-08 01:23:25 +05:30
# rubocop: enable CodeReuse/ActiveRecord
private
attr_reader :stage, :query, :params
2021-04-17 20:07:23 +05:30
end
end
end
end