Move counts on GeoNodeStatus to finders

parent b7ef0a91
......@@ -120,17 +120,6 @@ class GeoNode < ActiveRecord::Base
end
end
def lfs_objects
relation =
if selective_sync?
LfsObject.joins(:projects).where(projects: { id: projects })
else
LfsObject.all
end
relation.with_files_stored_locally
end
def projects
if selective_sync?
Project.where(namespace_id: Gitlab::GroupHierarchy.new(namespaces).base_and_descendants.select(:id))
......
......@@ -63,9 +63,9 @@ class GeoNodeStatus < ActiveRecord::Base
latest_event = Geo::EventLog.latest_event
self.last_event_id = latest_event&.id
self.last_event_date = latest_event&.created_at
self.repositories_count = geo_node.projects.count
self.lfs_objects_count = geo_node.lfs_objects.count
self.attachments_count = attachments_finder.uploads.count
self.repositories_count = projects_finder.count_projects
self.lfs_objects_count = lfs_objects_finder.count_lfs_objects
self.attachments_count = attachments_finder.count_attachments
self.last_successful_status_check_at = Time.now
if Gitlab::Geo.secondary?
......@@ -76,8 +76,8 @@ class GeoNodeStatus < ActiveRecord::Base
self.repositories_failed_count = projects_finder.count_failed_project_registries
self.lfs_objects_synced_count = lfs_objects_finder.count_synced_lfs_objects
self.lfs_objects_failed_count = lfs_objects_finder.count_failed_lfs_objects
self.attachments_synced_count = attachments_finder.find_synced_attachments.count
self.attachments_failed_count = attachments_finder.find_failed_attachments.count
self.attachments_synced_count = attachments_finder.count_synced_attachments
self.attachments_failed_count = attachments_finder.count_failed_attachments
end
self
......
module Geo
class AttachmentRegistryFinder < RegistryFinder
def count_attachments
uploads.count
end
def count_synced_attachments
find_synced_attachments.count
end
def count_failed_attachments
find_failed_attachments.count
end
def find_synced_attachments
relation =
if use_legacy_queries?
......
......@@ -95,7 +95,7 @@ module Geo
registry_ids = legacy_pluck_registry_ids(file_types: :lfs, except_registry_ids: except_registry_ids)
legacy_filter_registry_ids(
current_node.lfs_objects,
lfs_objects_finder.lfs_objects,
registry_ids,
LfsObject.table_name
)
......@@ -136,5 +136,9 @@ module Geo
def attachments_finder
@attachments_finder ||= AttachmentRegistryFinder.new(current_node: current_node)
end
def lfs_objects_finder
@lfs_objects_finder ||= LfsObjectRegistryFinder.new(current_node: current_node)
end
end
end
module Geo
class LfsObjectRegistryFinder < RegistryFinder
def count_lfs_objects
lfs_objects.count
end
def count_synced_lfs_objects
relation =
if selective_sync?
......@@ -22,6 +26,17 @@ module Geo
relation.count
end
def lfs_objects
relation =
if selective_sync?
LfsObject.joins(:projects).where(projects: { id: current_node.projects })
else
LfsObject.all
end
relation.with_files_stored_locally
end
private
def find_synced_lfs_objects_registries
......
module Geo
class ProjectRegistryFinder < RegistryFinder
def count_projects
current_node.projects.count
end
def count_synced_project_registries
relation =
if selective_sync?
......
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