Move duplicated methods to the parent class

With these changes we make our finders more
maintainable.
parent a557ef63
......@@ -2,29 +2,6 @@
module Geo
class ContainerRepositoryRegistryFinder < RegistryFinder
def registry_count
registry_class.count
end
alias_method :count_registry, :registry_count
def count_synced
registry_class.synced.count
end
def count_failed
registry_class.failed.count
end
def find_registry_differences(range)
source_ids = replicables.id_in(range).pluck_primary_key
tracked_ids = registry_class.pluck_model_ids_in_range(range)
untracked_ids = source_ids - tracked_ids
unused_tracked_ids = tracked_ids - source_ids
[untracked_ids, unused_tracked_ids]
end
# Returns Geo::ContainerRepositoryRegistry records that have never been synced.
#
# Does not care about selective sync, because it considers the Registry
......
......@@ -2,29 +2,6 @@
module Geo
class DesignRegistryFinder < RegistryFinder
def registry_count
registry_class.count
end
alias_method :count_registry, :registry_count
def count_synced
registry_class.synced.count
end
def count_failed
registry_class.failed.count
end
def find_registry_differences(range)
source_ids = replicables.id_in(range).pluck_primary_key
tracked_ids = registry_class.pluck_model_ids_in_range(range)
untracked_ids = source_ids - tracked_ids
unused_tracked_ids = tracked_ids - source_ids
[untracked_ids, unused_tracked_ids]
end
# Returns Geo::DesignRegistry records that have never been synced.
#
# Does not care about selective sync, because it considers the Registry
......
......@@ -2,26 +2,6 @@
module Geo
class FileRegistryFinder < RegistryFinder
# @!method registry_count
# Return a count of the registry records for the tracked file_type(s)
def registry_count
registry_class.count
end
# @!method count_synced
# Return a count of the registry records for the tracked file_type(s)
# that are synced
def count_synced
registry_class.synced.count
end
# @!method count_failed
# Return a count of the registry records for the tracked file_type(s)
# that are sync failed
def count_failed
registry_class.failed.count
end
# @!method count_synced_missing_on_primary
# Return a count of the registry records for the tracked file_type(s)
# that are synced and missing on the primary
......@@ -29,40 +9,6 @@ module Geo
registry_class.synced.missing_on_primary.count
end
# @!method count_registry
# Return a count of the registry records for the tracked file_type(s)
def count_registry
registry_class.count
end
# @!method find_registry_differences
# Returns untracked IDs as well as tracked IDs that are unused.
#
# Untracked IDs are model IDs that are supposed to be synced but don't yet
# have a registry entry.
#
# Unused tracked IDs are model IDs that are not supposed to be synced but
# already have a registry entry. For example:
#
# - orphaned registries
# - records that became excluded from selective sync
# - records that are in object storage, and `sync_object_storage` became
# disabled
#
# We compute both sets in this method to reduce the number of DB queries
# performed.
#
# @return [Array] the first element is an Array of untracked IDs, and the second element is an Array of tracked IDs that are unused
def find_registry_differences(range)
source_ids = replicables.id_in(range).pluck(replicable_primary_key) # rubocop:disable CodeReuse/ActiveRecord
tracked_ids = registry_class.pluck_model_ids_in_range(range)
untracked_ids = source_ids - tracked_ids
unused_tracked_ids = tracked_ids - source_ids
[untracked_ids, unused_tracked_ids]
end
# @!method find_never_synced_registries
# Return an ActiveRecord::Relation of the registry records for the
# tracked file_type(s) that have never been synced.
......@@ -128,28 +74,6 @@ module Geo
end
# rubocop:enable CodeReuse/ActiveRecord
# @!method registry_class
# Return an ActiveRecord::Base class for the tracked file_type(s)
def registry_class
raise NotImplementedError,
"#{self.class} does not implement #{__method__}"
end
# @!method replicables
# Return an ActiveRecord::Relation of the replicable records for the
# tracked file_type(s)
def replicables
raise NotImplementedError,
"#{self.class} does not implement #{__method__}"
end
# @!method registry_class
# Return the fully qualified name of the replicable primary key for the
# tracked file_type(s)
def replicable_primary_key
registry_class::MODEL_CLASS.arel_table[:id]
end
def local_storage_only?
!current_node&.sync_object_storage
end
......
......@@ -10,6 +10,70 @@ module Geo
@current_node_id = current_node_id
end
# @!method find_registry_differences
# Returns untracked IDs as well as tracked IDs that are unused.
#
# Untracked IDs are model IDs that are supposed to be synced but don't yet
# have a registry entry.
#
# Unused tracked IDs are model IDs that are not supposed to be synced but
# already have a registry entry. For example:
#
# - orphaned registries
# - records that became excluded from selective sync
# - records that are in object storage, and `sync_object_storage` became
# disabled
#
# We compute both sets in this method to reduce the number of DB queries
# performed.
#
# @return [Array] the first element is an Array of untracked IDs, and the second element is an Array of tracked IDs that are unused
def find_registry_differences(range)
source_ids = replicables.id_in(range).pluck(replicable_primary_key) # rubocop:disable CodeReuse/ActiveRecord
tracked_ids = registry_class.pluck_model_ids_in_range(range)
untracked_ids = source_ids - tracked_ids
unused_tracked_ids = tracked_ids - source_ids
[untracked_ids, unused_tracked_ids]
end
# @!method registry_class
# Return an ActiveRecord::Base class for the tracked type
def registry_class
raise NotImplementedError,
"#{self.class} does not implement #{__method__}"
end
# @!method replicables
# Return an ActiveRecord::Relation of the replicable records for the
# tracked file_type(s)
def replicables
raise NotImplementedError,
"#{self.class} does not implement #{__method__}"
end
# @!method registry_count
# Return a count of the registry records for the tracked type(s)
def registry_count
registry_class.count
end
alias_method :count_registry, :registry_count
# @!method count_synced
# Return a count of the registry records for the tracked type
# that are synced
def count_synced
registry_class.synced.count
end
# @!method count_failed
# Return a count of the registry records for the tracked type
# that are sync failed
def count_failed
registry_class.failed.count
end
private
def current_node
......@@ -17,5 +81,12 @@ module Geo
GeoNode.find(current_node_id) if current_node_id
end
end
# @!method registry_class
# Return the fully qualified name of the replicable primary key for the
# tracked file_type(s)
def replicable_primary_key
registry_class::MODEL_CLASS.arel_table[:id]
end
end
end
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