Commit 14e6efc0 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'mk/refactor-replicable-package-files-scope' into 'master'

Geo: Improve performance of package files queries

Closes #222617

See merge request gitlab-org/gitlab!42294
parents 9bbb8d65 cc653969
...@@ -29,20 +29,8 @@ module EE ...@@ -29,20 +29,8 @@ module EE
def selective_sync_scope def selective_sync_scope
return self.all unless ::Gitlab::Geo.current_node.selective_sync? return self.all unless ::Gitlab::Geo.current_node.selective_sync?
query = ::Packages::Package.where(project_id: ::Gitlab::Geo.current_node.projects).select(:id) self.joins(:package)
cte = ::Gitlab::SQL::CTE.new(:restricted_packages, query) .where('packages_packages.project_id IN (?)', ::Gitlab::Geo.current_node.projects.select(:id))
replicable_table = self.arel_table
inner_join_restricted_packages =
cte.table
.join(replicable_table, Arel::Nodes::InnerJoin)
.on(cte.table[:id].eq(replicable_table[:package_id]))
.join_sources
self
.with(cte.to_arel)
.from(cte.table)
.joins(inner_join_restricted_packages)
end end
end end
......
---
title: 'Geo: Improve performance of package files queries'
merge_request: 42294
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