Commit cc653969 authored by Mike Kozono's avatar Mike Kozono

Refactor replicable package files scope

to improve performance and readability.
parent 3d9f7a44
......@@ -29,20 +29,8 @@ module EE
def selective_sync_scope
return self.all unless ::Gitlab::Geo.current_node.selective_sync?
query = ::Packages::Package.where(project_id: ::Gitlab::Geo.current_node.projects).select(:id)
cte = ::Gitlab::SQL::CTE.new(:restricted_packages, query)
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)
self.joins(:package)
.where('packages_packages.project_id IN (?)', ::Gitlab::Geo.current_node.projects.select(:id))
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