Commit 16f107cb authored by Toon Claes's avatar Toon Claes Committed by Douglas Barbosa Alexandre

Split out load_ methods and simplify condition

Don't put code in large if blocks, but do an early return instead.
parent 8ba8815c
...@@ -145,13 +145,6 @@ class GeoNodeStatus < ApplicationRecord ...@@ -145,13 +145,6 @@ class GeoNodeStatus < ApplicationRecord
end end
def load_data_from_current_node def load_data_from_current_node
self.status_message =
begin
HealthCheck::Utils.process_checks(['geo'])
rescue NotImplementedError => e
e.to_s
end
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
...@@ -175,14 +168,25 @@ class GeoNodeStatus < ApplicationRecord ...@@ -175,14 +168,25 @@ class GeoNodeStatus < ApplicationRecord
self.hashed_storage_attachments_max_id = Geo::HashedStorageAttachmentsEvent.maximum(:id) self.hashed_storage_attachments_max_id = Geo::HashedStorageAttachmentsEvent.maximum(:id)
self.projects_count = geo_node.projects.count self.projects_count = geo_node.projects.count
load_status_message
load_primary_data load_primary_data
load_secondary_data load_secondary_data
self self
end end
def load_status_message
self.status_message =
begin
HealthCheck::Utils.process_checks(['geo'])
rescue NotImplementedError => e
e.to_s
end
end
def load_primary_data def load_primary_data
if Gitlab::Geo.primary? return unless Gitlab::Geo.primary?
self.lfs_objects_count = LfsObject.syncable.count self.lfs_objects_count = LfsObject.syncable.count
self.job_artifacts_count = Ci::JobArtifact.syncable.count self.job_artifacts_count = Ci::JobArtifact.syncable.count
self.attachments_count = Upload.syncable.count self.attachments_count = Upload.syncable.count
...@@ -197,14 +201,13 @@ class GeoNodeStatus < ApplicationRecord ...@@ -197,14 +201,13 @@ class GeoNodeStatus < ApplicationRecord
self.wikis_checksummed_count = repository_verification_finder.count_verified_wikis self.wikis_checksummed_count = repository_verification_finder.count_verified_wikis
self.wikis_checksum_failed_count = repository_verification_finder.count_verification_failed_wikis self.wikis_checksum_failed_count = repository_verification_finder.count_verification_failed_wikis
end end
self.repositories_checked_count = Project.where.not(last_repository_check_at: nil).count
self.repositories_checked_failed_count = Project.where(last_repository_check_failed: true).count
end
end end
def load_secondary_data # rubocop:disable Metrics/AbcSize def load_secondary_data # rubocop:disable Metrics/AbcSize
if Gitlab::Geo.secondary? return unless Gitlab::Geo.secondary?
self.db_replication_lag_seconds = Gitlab::Geo::HealthCheck.new.db_replication_lag_seconds self.db_replication_lag_seconds = Gitlab::Geo::HealthCheck.new.db_replication_lag_seconds
self.cursor_last_event_id = current_cursor_last_event_id self.cursor_last_event_id = current_cursor_last_event_id
self.cursor_last_event_date = Geo::EventLog.find_by(id: self.cursor_last_event_id)&.created_at self.cursor_last_event_date = Geo::EventLog.find_by(id: self.cursor_last_event_id)&.created_at
...@@ -233,10 +236,10 @@ class GeoNodeStatus < ApplicationRecord ...@@ -233,10 +236,10 @@ class GeoNodeStatus < ApplicationRecord
self.repositories_checked_count = Geo::ProjectRegistry.where.not(last_repository_check_at: nil).count self.repositories_checked_count = Geo::ProjectRegistry.where.not(last_repository_check_at: nil).count
self.repositories_checked_failed_count = Geo::ProjectRegistry.where(last_repository_check_failed: true).count self.repositories_checked_failed_count = Geo::ProjectRegistry.where(last_repository_check_failed: true).count
end end
end
def load_verification_data def load_verification_data
if repository_verification_enabled return unless repository_verification_enabled
self.repositories_verified_count = registries_for_verified_projects(:repository).count self.repositories_verified_count = registries_for_verified_projects(:repository).count
self.repositories_verification_failed_count = registries_for_verification_failed_projects(:repository).count self.repositories_verification_failed_count = registries_for_verification_failed_projects(:repository).count
self.repositories_checksum_mismatch_count = registries_for_mismatch_projects(:repository).count self.repositories_checksum_mismatch_count = registries_for_mismatch_projects(:repository).count
...@@ -246,7 +249,6 @@ class GeoNodeStatus < ApplicationRecord ...@@ -246,7 +249,6 @@ class GeoNodeStatus < ApplicationRecord
self.repositories_retrying_verification_count = registries_retrying_verification(:repository).count self.repositories_retrying_verification_count = registries_retrying_verification(:repository).count
self.wikis_retrying_verification_count = registries_retrying_verification(:wiki).count self.wikis_retrying_verification_count = registries_retrying_verification(:wiki).count
end end
end
def current_cursor_last_event_id def current_cursor_last_event_id
return unless Gitlab::Geo.secondary? return unless Gitlab::Geo.secondary?
......
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