Commit 27fc442d authored by Michael Kozono's avatar Michael Kozono

Merge branch...

Merge branch '10286-geo-sql-statement-times-out-whilst-determining-lfs-objects-to-sync' into 'master'

Geo - Rewrite query to determine LFS objects to sync with selective sync

Closes #10286

See merge request gitlab-org/gitlab!19051
parents ccdab743 683c12d0
......@@ -35,7 +35,20 @@ module Geo
def lfs_objects
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
def lfs_object_registries
......
......@@ -7,6 +7,8 @@ module Geo
belongs_to :lfs_object, class_name: 'Geo::Fdw::LfsObject', inverse_of: :projects
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
......@@ -15,7 +15,7 @@ module Geo
# rubocop: disable CodeReuse/ActiveRecord
def convert_resource_relation_to_job_args(relation)
relation.pluck(:id, :uploader)
.map { |id, uploader| [uploader.sub(/Uploader\z/, '').underscore, id] }
.map! { |id, uploader| [uploader.sub(/Uploader\z/, '').underscore, id] }
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -50,13 +50,13 @@ module Geo
# rubocop: disable CodeReuse/ActiveRecord
def convert_resource_relation_to_job_args(relation)
relation.pluck(:id).map { |id| [self.class::FILE_SERVICE_OBJECT_TYPE.to_s, id] }
relation.pluck(relation.model.arel_table[:id]).map! { |id| [self.class::FILE_SERVICE_OBJECT_TYPE.to_s, id] }
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def convert_registry_relation_to_job_args(relation)
relation.pluck(self.class::RESOURCE_ID_KEY).map { |id| [self.class::FILE_SERVICE_OBJECT_TYPE.to_s, id] }
relation.pluck(self.class::RESOURCE_ID_KEY).map! { |id| [self.class::FILE_SERVICE_OBJECT_TYPE.to_s, id] }
end
# rubocop: enable CodeReuse/ActiveRecord
end
......
---
title: Geo - Improve query performance to determine LFS objects to sync when selective
sync is enabled
merge_request: 19051
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