From a8e849bb0d621f300fb5239699749e7b88e3cf03 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Thu, 6 Jul 2017 07:30:21 -0400 Subject: Mirror: only hit all sites for upload and delete The mirror service exists for the purpose of migration, where all blobs exist in the primary subservice and a subset of blobs exist in the secondary subservice. Since the primary subservice is the source of truth until a migration is completed, operations like existence checks need not be performed against the secondary subservices. --- lib/active_storage/service/mirror_service.rb | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/lib/active_storage/service/mirror_service.rb b/lib/active_storage/service/mirror_service.rb index 2a3518e59e..0d37ad96a3 100644 --- a/lib/active_storage/service/mirror_service.rb +++ b/lib/active_storage/service/mirror_service.rb @@ -1,6 +1,10 @@ +require "active_support/core_ext/module/delegation" + class ActiveStorage::Service::MirrorService < ActiveStorage::Service attr_reader :services + delegate :download, :exist?, :url, :byte_size, :checksum, to: :primary_service + def initialize(services:) @services = services end @@ -12,31 +16,10 @@ class ActiveStorage::Service::MirrorService < ActiveStorage::Service end end - def download(key) - services.detect { |service| service.exist?(key) }.download(key) - end - def delete(key) perform_across_services :delete, key end - def exist?(key) - perform_across_services(:exist?, key).any? - end - - - def url(key, **options) - primary_service.url(key, **options) - end - - def byte_size(key) - primary_service.byte_size(key) - end - - def checksum(key) - primary_service.checksum(key) - end - private def primary_service services.first -- cgit v1.2.3