Skip to content

Optimize deployment counters related to the ::Deployment

Fix the queries for both monthly, and all-times version of the queries with batch counters enabled.

Feature.enable(:usage_ping_batch_counter)

# 1 Locations https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/ee/gitlab/usage_data.rb
time_period = { }

deployments: distinct_count(::Deployment.where(time_period), :user_id),
failed_deployments: distinct_count(::Deployment.failed.where(time_period), :user_id),
successful_deployments: distinct_count(::Deployment.success.where(time_period), :user_id)


# 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 }

# Same above for the 28-days "monthly" period

# 3  Locations https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/usage_data.rb

deployments: count(Deployment),
successful_deployments: count(Deployment.success),
failed_deployments: count(Deployment.failed),

Guide to optimize the counter

Edited by Alina Mihaila