Enable batch counting for some individual queries
Batch is disabled for the below counters just because the querying required a refactoring
- Remove
, batch: false
which defaults to batch beingtrue
- Test the specs
bundle exec rspec -fd ee/spec/lib/ee/gitlab/usage_data_spec.rb spec/lib/gitlab/usage_data_spec.rb
- Refactor the query and the idea to make it batch countable
result of -1)
Priority queries that currently timeout on GitLab.com (# 1 Locations https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/usage_data.rb
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27093
# service_counts = count(Service.active.where(template: false).where.not(type: 'JiraService').group(:type), fallback: Hash.new(-1), batch: false)
# 2 Locations https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/ee/gitlab/usage_data.rb
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27110
# projects_mirrored_with_pipelines_enabled: count(::Project.mirrored_with_enabled_pipelines, batch: false),
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27352
# template_repositories: count(::Project.with_repos_templates, batch: false) + count(::Project.with_groups_level_repos_templates, batch: false)
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/26296
# results = count(::Ci::Build.where(name: types.keys).group(:name), fallback: Hash.new(-1), batch: false)
Other queries
# 1 Locations https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/usage_data.rb
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27455
# results[:projects_jira_active] = count(services, batch: false)
# results[:projects_jira_active] += count(services, batch: false)
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/26887
# clusters_platforms_eks: count(::Clusters::Cluster.aws_installed.enabled, batch: false),
# clusters_platforms_gke: count(::Clusters::Cluster.gcp_installed.enabled, batch: false),
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/26972
# issues_using_zoom_quick_actions: count(ZoomMeeting.select(:issue_id).distinct, batch: false),
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/26982
# projects_with_alerts_service_enabled: count(AlertsService.active, batch: false),
# 2 Locations https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/ee/gitlab/usage_data.rb
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27455
# users_with_projects_added = count(UsersOpsDashboardProject.distinct_users(::User.active), batch: false)
# projects_with_packages: count(::Packages::Package.select('distinct project_id'), batch: false),
# operations_dashboard_users_with_projects_added: count(UsersOpsDashboardProject.distinct_users(::User.active).where(time_period), batch: false),
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27526
# projects_enforcing_code_owner_approval: count(::Project.without_deleted.non_archived.requiring_code_owner_approval, batch: false),
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27533
# projects_reporting_ci_cd_back_to_github: count(::GithubService.without_defaults.active, batch: false),
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27540
# projects_with_tracing_enabled: count(ProjectTracingSetting, batch: false),
# Fixed by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27544
# projects_with_prometheus_alerts: count(PrometheusAlert.distinct_projects, batch: false),
Edited by Alex Buijs