Commit 9d8d5c63 authored by Andreas Brandl's avatar Andreas Brandl

Merge branch '220209-optimize-container-repository-query' into 'master'

Optimize container repository query

See merge request gitlab-org/gitlab!34364
parents e1dedad4 86174a1b
...@@ -16,7 +16,13 @@ class ContainerRepository < ApplicationRecord ...@@ -16,7 +16,13 @@ class ContainerRepository < ApplicationRecord
scope :ordered, -> { order(:name) } scope :ordered, -> { order(:name) }
scope :with_api_entity_associations, -> { preload(project: [:route, { namespace: :route }]) } scope :with_api_entity_associations, -> { preload(project: [:route, { namespace: :route }]) }
scope :for_group_and_its_subgroups, ->(group) do scope :for_group_and_its_subgroups, ->(group) do
where(project_id: Project.for_group_and_its_subgroups(group).with_container_registry.select(:id)) project_scope = Project
.for_group_and_its_subgroups(group)
.with_container_registry
.select(:id)
ContainerRepository
.joins("INNER JOIN (#{project_scope.to_sql}) projects on projects.id=container_repositories.project_id")
end end
scope :search_by_name, ->(query) { fuzzy_search(query, [:name], use_minimum_char_limit: false) } scope :search_by_name, ->(query) { fuzzy_search(query, [:name], use_minimum_char_limit: false) }
......
---
title: Optimize container repository for groups query
merge_request: 34364
author:
type: performance
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