Refactoring Lfs Object finder to count registries instead of using FDW

parent c01e9041
......@@ -76,8 +76,8 @@ class GeoNodeStatus < ActiveRecord::Base
self.repositories_failed_count = geo_node.project_registries.failed.count
lfs_objects_finder = Geo::LfsObjectRegistryFinder.new(current_node: geo_node)
self.lfs_objects_synced_count = lfs_objects_finder.find_synced_lfs_objects.count
self.lfs_objects_failed_count = lfs_objects_finder.find_failed_lfs_objects.count
self.lfs_objects_synced_count = lfs_objects_finder.count_synced_lfs_objects
self.lfs_objects_failed_count = lfs_objects_finder.count_failed_lfs_objects
attachments_finder = Geo::AttachmentRegistryFinder.new(current_node: geo_node)
self.attachments_synced_count = attachments_finder.find_synced_attachments.count
......
module Geo
class LfsObjectRegistryFinder < RegistryFinder
def find_synced_lfs_objects
def count_synced_lfs_objects
relation =
if fdw?
fdw_find_synced_lfs_objects
else
if selective_sync?
legacy_find_synced_lfs_objects
end
relation
end
def find_failed_lfs_objects
relation =
if fdw?
fdw_find_failed_lfs_objects
else
legacy_find_failed_lfs_objects
find_synced_lfs_objects_registries
end
relation
relation.count
end
private
def lfs_objects
lfs_object_model = fdw? ? Geo::Fdw::LfsObject : LfsObject
def count_failed_lfs_objects
relation =
if selective_sync?
lfs_object_model.joins(:projects).where(projects: { id: current_node.projects })
legacy_find_failed_lfs_objects
else
lfs_object_model.all
find_failed_lfs_objects_registries
end
relation.with_files_stored_locally
relation.count
end
#
# FDW accessors
#
def fdw_table
Geo::Fdw::LfsObject.table_name
end
private
def fdw_find_synced_lfs_objects
lfs_objects.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id")
.merge(Geo::FileRegistry.lfs_objects)
.merge(Geo::FileRegistry.synced)
def find_synced_lfs_objects_registries
Geo::FileRegistry.lfs_objects.synced
end
def fdw_find_failed_lfs_objects
lfs_objects.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id")
.merge(Geo::FileRegistry.lfs_objects)
.merge(Geo::FileRegistry.failed)
def find_failed_lfs_objects_registries
Geo::FileRegistry.lfs_objects.failed
end
#
# Legacy accessors (non FDW)
#
def legacy_find_synced_lfs_objects
legacy_find_lfs_objects(Geo::FileRegistry.lfs_objects.synced.pluck(:file_id))
end
......@@ -72,6 +43,10 @@ module Geo
def legacy_find_lfs_objects(registry_file_ids)
return LfsObject.none if registry_file_ids.empty?
lfs_objects = LfsObject.joins(:projects)
.where(projects: { id: current_node.projects })
.with_files_stored_locally
joined_relation = lfs_objects.joins(<<~SQL)
INNER JOIN
(VALUES #{registry_file_ids.map { |id| "(#{id})" }.join(',')})
......
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