Move counts on GeoNodeStatus to finders

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