aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2017-07-06 07:30:21 -0400
committerGeorge Claghorn <george@basecamp.com>2017-07-06 07:30:21 -0400
commita8e849bb0d621f300fb5239699749e7b88e3cf03 (patch)
tree5e174a37cf13aff74211c46cf7d16a0c77cc5df3 /lib
parent35d5bddabcd8f0eccc7de3ddf60431ea196508a1 (diff)
downloadrails-a8e849bb0d621f300fb5239699749e7b88e3cf03.tar.gz
rails-a8e849bb0d621f300fb5239699749e7b88e3cf03.tar.bz2
rails-a8e849bb0d621f300fb5239699749e7b88e3cf03.zip
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/active_storage/service/mirror_service.rb25
1 files 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