2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Analytics
|
|
|
|
module CycleAnalytics
|
|
|
|
# Arguments:
|
2023-04-23 21:23:45 +05:30
|
|
|
# stage - an instance of CycleAnalytics::Stage
|
2019-12-21 20:55:43 +05:30
|
|
|
# params:
|
|
|
|
# current_user: an instance of User
|
|
|
|
# from: DateTime
|
|
|
|
# to: DateTime
|
|
|
|
class DataCollector
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
MAX_COUNT = 1001
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
delegate :serialized_records, to: :records_fetcher
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def initialize(stage:, params: {})
|
|
|
|
@stage = stage
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def records_fetcher
|
|
|
|
strong_memoize(:records_fetcher) do
|
2021-12-11 22:18:48 +05:30
|
|
|
if use_aggregated_data_collector?
|
|
|
|
aggregated_data_collector.records_fetcher
|
|
|
|
else
|
|
|
|
RecordsFetcher.new(stage: stage, query: query, params: params)
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def median
|
|
|
|
strong_memoize(:median) do
|
2021-12-11 22:18:48 +05:30
|
|
|
if use_aggregated_data_collector?
|
|
|
|
aggregated_data_collector.median
|
|
|
|
else
|
|
|
|
Median.new(stage: stage, query: query, params: params)
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
def average
|
|
|
|
strong_memoize(:average) do
|
2021-06-08 01:23:25 +05:30
|
|
|
Average.new(stage: stage, query: query, params: params)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def count
|
|
|
|
strong_memoize(:count) do
|
2021-12-11 22:18:48 +05:30
|
|
|
if use_aggregated_data_collector?
|
|
|
|
aggregated_data_collector.count
|
|
|
|
else
|
|
|
|
limit_count
|
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :stage, :params
|
|
|
|
|
|
|
|
def query
|
2022-04-04 11:22:00 +05:30
|
|
|
query_builder.build
|
|
|
|
end
|
|
|
|
|
|
|
|
def query_builder
|
|
|
|
@query_builder ||= BaseQueryBuilder.new(stage: stage, params: params)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
# 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
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
def aggregated_data_collector
|
|
|
|
@aggregated_data_collector ||= Aggregated::DataCollector.new(stage: stage, params: params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def use_aggregated_data_collector?
|
|
|
|
params.fetch(:use_aggregated_data_collector, false)
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Gitlab::Analytics::CycleAnalytics::DataCollector.prepend_mod_with('Gitlab::Analytics::CycleAnalytics::DataCollector')
|