Rewrite the query to retrieve LFS objects using CTE

parent 0e7baa35
...@@ -35,7 +35,20 @@ module Geo ...@@ -35,7 +35,20 @@ module Geo
def lfs_objects def lfs_objects
return Geo::Fdw::LfsObject.all unless selective_sync? return Geo::Fdw::LfsObject.all unless selective_sync?
Geo::Fdw::LfsObject.project_id_in(projects) query = Geo::Fdw::LfsObjectsProject.project_id_in(projects).select(:lfs_object_id)
cte = Gitlab::SQL::CTE.new(:restricted_lfs_objects, query)
fdw_lfs_object_table = Geo::Fdw::LfsObject.arel_table
inner_join_restricted_lfs_objects =
cte.table
.join(fdw_lfs_object_table, Arel::Nodes::InnerJoin)
.on(cte.table[:lfs_object_id].eq(fdw_lfs_object_table[:id]))
.join_sources
Geo::Fdw::LfsObject
.with(cte.to_arel)
.from(cte.table)
.joins(inner_join_restricted_lfs_objects)
end end
def lfs_object_registries def lfs_object_registries
......
...@@ -7,6 +7,8 @@ module Geo ...@@ -7,6 +7,8 @@ module Geo
belongs_to :lfs_object, class_name: 'Geo::Fdw::LfsObject', inverse_of: :projects belongs_to :lfs_object, class_name: 'Geo::Fdw::LfsObject', inverse_of: :projects
belongs_to :project, class_name: 'Geo::Fdw::Project', inverse_of: :lfs_objects belongs_to :project, class_name: 'Geo::Fdw::Project', inverse_of: :lfs_objects
scope :project_id_in, ->(ids) { joins(:project).merge(Geo::Fdw::Project.id_in(ids)) }
end end
end end
end end
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