Commit e3c69613 authored by Alex Buijs's avatar Alex Buijs

Optimize query for usage ping

Query by adding an index and using batch counting
parent 7d8ed431
---
title: Optimize template_repositories query by using batch counting
merge_request: 27352
author:
type: performance
# frozen_string_literal: true
class AddIndexOnNamespaceIdAndIdToProjects < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :projects, [:namespace_id, :id]
remove_concurrent_index :projects, :namespace_id
end
def down
add_concurrent_index :projects, :namespace_id
remove_concurrent_index :projects, [:namespace_id, :id]
end
end
......@@ -9657,7 +9657,7 @@ CREATE INDEX index_projects_on_name_and_id ON public.projects USING btree (name,
CREATE INDEX index_projects_on_name_trigram ON public.projects USING gin (name public.gin_trgm_ops);
CREATE INDEX index_projects_on_namespace_id ON public.projects USING btree (namespace_id);
CREATE INDEX index_projects_on_namespace_id_and_id ON public.projects USING btree (namespace_id, id);
CREATE INDEX index_projects_on_path_and_id ON public.projects USING btree (path, id);
......@@ -12702,6 +12702,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20200313101649'),
('20200313123934'),
('20200316111759'),
('20200316162648'),
('20200316173312'),
('20200317142110'),
('20200318152134'),
......
......@@ -157,7 +157,7 @@ module EE
projects_with_packages: count(::Packages::Package.select('distinct project_id'), batch: false),
projects_with_prometheus_alerts: distinct_count(PrometheusAlert, :project_id),
projects_with_tracing_enabled: count(ProjectTracingSetting),
template_repositories: count(::Project.with_repos_templates, batch: false) + count(::Project.with_groups_level_repos_templates, batch: false)
template_repositories: count(::Project.with_repos_templates) + count(::Project.with_groups_level_repos_templates)
},
service_desk_counts,
security_products_usage,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment