Commit c08d4160 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre Committed by Ash McKenzie

Refactor the Geo::AttachmentRegistryFinder

Remove some unnecessary methods after we removed the support
for legacy queries.
parent ea42591b
...@@ -2,24 +2,32 @@ ...@@ -2,24 +2,32 @@
module Geo module Geo
class AttachmentRegistryFinder < FileRegistryFinder class AttachmentRegistryFinder < FileRegistryFinder
def initialize(current_node:)
@current_node = Geo::Fdw::GeoNode.find(current_node.id)
end
def count_registry
Geo::FileRegistry.attachments.count
end
def count_syncable def count_syncable
syncable.count syncable.count
end end
def count_synced def count_synced
attachments_synced.count registries_for_attachments.syncable.merge(Geo::FileRegistry.synced).count
end end
def count_failed def count_failed
attachments_failed.count registries_for_attachments.syncable.merge(Geo::FileRegistry.failed).count
end end
def count_synced_missing_on_primary def count_synced_missing_on_primary
attachments_synced_missing_on_primary.count registries_for_attachments
end .syncable
.merge(Geo::FileRegistry.synced)
def count_registry .merge(Geo::FileRegistry.missing_on_primary)
Geo::FileRegistry.attachments.count .count
end end
def syncable def syncable
...@@ -42,13 +50,22 @@ module Geo ...@@ -42,13 +50,22 @@ module Geo
# @param [Array<Integer>] except_file_ids ids that will be ignored from the query # @param [Array<Integer>] except_file_ids ids that will be ignored from the query
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_unsynced(batch_size:, except_file_ids: []) def find_unsynced(batch_size:, except_file_ids: [])
attachments_unsynced(except_file_ids: except_file_ids).limit(batch_size) attachments
.missing_file_registry
.syncable
.id_not_in(except_file_ids)
.limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local(batch_size:, except_file_ids: []) def find_migrated_local(batch_size:, except_file_ids: [])
attachments_migrated_local(except_file_ids: except_file_ids).limit(batch_size) attachments
.inner_join_file_registry
.with_files_stored_remotely
.merge(Geo::FileRegistry.attachments)
.id_not_in(except_file_ids)
.limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
...@@ -77,46 +94,12 @@ module Geo ...@@ -77,46 +94,12 @@ module Geo
private private
def fdw_geo_node def attachments
@fdw_geo_node ||= Geo::Fdw::GeoNode.find(current_node.id) current_node.attachments
end end
def registries_for_attachments def registries_for_attachments
attachments.inner_join_file_registry.merge(Geo::FileRegistry.attachments) attachments.inner_join_file_registry.merge(Geo::FileRegistry.attachments)
end end
def attachments
fdw_geo_node.attachments
end
def attachments_synced
registries_for_attachments.syncable.merge(Geo::FileRegistry.synced)
end
def attachments_migrated_local(except_file_ids:)
attachments
.inner_join_file_registry
.with_files_stored_remotely
.merge(Geo::FileRegistry.attachments)
.id_not_in(except_file_ids)
end
def attachments_unsynced(except_file_ids:)
attachments
.missing_file_registry
.syncable
.id_not_in(except_file_ids)
end
def attachments_failed
registries_for_attachments.syncable.merge(Geo::FileRegistry.failed)
end
def attachments_synced_missing_on_primary
registries_for_attachments
.syncable
.merge(Geo::FileRegistry.synced)
.merge(Geo::FileRegistry.missing_on_primary)
end
end end
end end
require 'spec_helper' require 'spec_helper'
describe Geo::AttachmentRegistryFinder, :geo do describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
include ::EE::GeoHelpers include ::EE::GeoHelpers
# Using let() instead of set() because set() does not work properly # Using let() instead of set() because set() does not work properly
...@@ -475,8 +475,6 @@ describe Geo::AttachmentRegistryFinder, :geo do ...@@ -475,8 +475,6 @@ describe Geo::AttachmentRegistryFinder, :geo do
end end
end end
context 'FDW', :geo_fdw do include_examples 'counts all the things'
include_examples 'counts all the things' include_examples 'finds all the things'
include_examples 'finds all the things'
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