diff options
Diffstat (limited to 'lib/gitlab/analytics')
-rw-r--r-- | lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb | 34 | ||||
-rw-r--r-- | lib/gitlab/analytics/instance_statistics/workers_argument_builder.rb | 27 |
2 files changed, 49 insertions, 12 deletions
diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb index c5f843d5f1a..4bb225b63f1 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb @@ -18,24 +18,46 @@ module Gitlab end def timestamp_projection - issue_metrics_table[:first_mentioned_in_commit_at] + Arel::Nodes::NamedFunction.new('COALESCE', column_list) end override :column_list def column_list - [timestamp_projection] + [ + issue_metrics_table[:first_mentioned_in_commit_at], + mr_metrics_table[:first_commit_at] + ] end # rubocop: disable CodeReuse/ActiveRecord def apply_query_customization(query) - issue_metrics_join = mr_closing_issues_table - .join(issue_metrics_table) + query + .joins(merge_requests_closing_issues_join) + .joins(issue_metrics_join) + .joins(mr_metrics_join) + end + # rubocop: enable CodeReuse/ActiveRecord + + def issue_metrics_join + mr_closing_issues_table + .join(issue_metrics_table, Arel::Nodes::OuterJoin) .on(mr_closing_issues_table[:issue_id].eq(issue_metrics_table[:issue_id])) .join_sources + end - query.joins(:merge_requests_closing_issues).joins(issue_metrics_join) + def merge_requests_closing_issues_join + mr_table + .join(mr_closing_issues_table, Arel::Nodes::OuterJoin) + .on(mr_table[:id].eq(mr_closing_issues_table[:merge_request_id])) + .join_sources + end + + def mr_metrics_join + mr_metrics_table + .join(mr_metrics_table, Arel::Nodes::OuterJoin) + .on(mr_metrics_table[:merge_request_id].eq(mr_table[:id])) + .join_sources end - # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/lib/gitlab/analytics/instance_statistics/workers_argument_builder.rb b/lib/gitlab/analytics/instance_statistics/workers_argument_builder.rb index 636bba22c23..54b3bbb3ce6 100644 --- a/lib/gitlab/analytics/instance_statistics/workers_argument_builder.rb +++ b/lib/gitlab/analytics/instance_statistics/workers_argument_builder.rb @@ -11,21 +11,36 @@ module Gitlab def execute measurement_identifiers.map do |measurement_identifier| - query_scope = ::Analytics::InstanceStatistics::Measurement::IDENTIFIER_QUERY_MAPPING[measurement_identifier]&.call + query_scope = query_mappings[measurement_identifier]&.call next if query_scope.nil? - # Determining the query range (id range) as early as possible in order to get more accurate counts. - start = query_scope.minimum(:id) - finish = query_scope.maximum(:id) - - [measurement_identifier, start, finish, recorded_at] + [measurement_identifier, *determine_start_and_finish(measurement_identifier, query_scope), recorded_at] end.compact end private attr_reader :measurement_identifiers, :recorded_at + + # Determining the query range (id range) as early as possible in order to get more accurate counts. + def determine_start_and_finish(measurement_identifier, query_scope) + queries = custom_min_max_queries[measurement_identifier] + + if queries + [queries[:minimum_query].call, queries[:maximum_query].call] + else + [query_scope.minimum(:id), query_scope.maximum(:id)] + end + end + + def custom_min_max_queries + ::Analytics::InstanceStatistics::Measurement.identifier_min_max_queries + end + + def query_mappings + ::Analytics::InstanceStatistics::Measurement.identifier_query_mapping + end end end end |