2019-10-10 21:06:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Analytics
|
|
|
|
module CycleAnalytics
|
|
|
|
# Arguments:
|
|
|
|
# stage - an instance of CycleAnalytics::ProjectStage or CycleAnalytics::GroupStage
|
|
|
|
# params:
|
|
|
|
# current_user: an instance of User
|
|
|
|
# from: DateTime
|
|
|
|
# to: DateTime
|
|
|
|
class DataCollector
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2021-04-21 09:09:15 +00:00
|
|
|
MAX_COUNT = 1001
|
|
|
|
|
2019-10-29 06:06:14 +00:00
|
|
|
delegate :serialized_records, to: :records_fetcher
|
|
|
|
|
2019-10-10 21:06:01 +00:00
|
|
|
def initialize(stage:, params: {})
|
|
|
|
@stage = stage
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def records_fetcher
|
|
|
|
strong_memoize(:records_fetcher) do
|
|
|
|
RecordsFetcher.new(stage: stage, query: query, params: params)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def median
|
|
|
|
strong_memoize(:median) do
|
|
|
|
Median.new(stage: stage, query: query)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-19 06:10:35 +00:00
|
|
|
def average
|
|
|
|
strong_memoize(:average) do
|
|
|
|
Average.new(stage: stage, query: query)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-21 09:09:15 +00:00
|
|
|
def count
|
|
|
|
strong_memoize(:count) do
|
|
|
|
limit_count
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-10 21:06:01 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :stage, :params
|
|
|
|
|
|
|
|
def query
|
|
|
|
BaseQueryBuilder.new(stage: stage, params: params).build
|
|
|
|
end
|
2021-04-21 09:09:15 +00:00
|
|
|
|
|
|
|
# Limiting the maximum number of records so the COUNT(*) query stays efficient for large groups.
|
|
|
|
# COUNT = 1001, show 1000+ on the UI
|
|
|
|
# COUNT < 1001, show the actual number on the UI
|
|
|
|
def limit_count
|
|
|
|
query.limit(MAX_COUNT).count
|
|
|
|
end
|
2019-10-10 21:06:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-22 18:06:00 +00:00
|
|
|
|
|
|
|
Gitlab::Analytics::CycleAnalytics::DataCollector.prepend_if_ee('EE::Gitlab::Analytics::CycleAnalytics::DataCollector')
|