Optimize ci_pipeline counters in usage data
Fix the queries for both monthly, and all-times version of the queries with batch counters enabled.
- 100 million records in gitlab.com
ci_pipelines
table
# 1 Locations https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/ee/gitlab/usage_data.rb
time_period = { }
# Same as below but works fine
# 2 Locations https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/ee/gitlab/usage_data.rb
time_period = { created_at: 28.days.ago..Time.current }
ci_external_pipelines: distinct_count(::Ci::Pipeline.external.where(time_period), :user_id),
ci_internal_pipelines: distinct_count(::Ci::Pipeline.internal.where(time_period), :user_id),
ci_pipeline_config_auto_devops: distinct_count(::Ci::Pipeline.auto_devops_source.where(time_period), :user_id),
ci_pipeline_config_repository: distinct_count(::Ci::Pipeline.repository_source.where(time_period), :user_id),
ci_pipelines: distinct_count(::Ci::Pipeline.where(time_period), :user_id),
Edited by Alper Akgun