Skip to content

Commit 3f2258a

Browse files
committed
Improve performance by parallelizing ActiveStorage::Service::MirrorService#delete and ActiveStorage::Service::MirrorService#delete_prefixed
1 parent a27a175 commit 3f2258a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

activestorage/lib/active_storage/service/mirror_service.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ def self.build(primary:, mirrors:, name:, configurator:, **options) # :nodoc:
3030

3131
def initialize(primary:, mirrors:)
3232
@primary, @mirrors = primary, mirrors
33+
@executor = Concurrent::ThreadPoolExecutor.new(
34+
min_threads: 1,
35+
max_threads: mirrors.size,
36+
max_queue: 0,
37+
fallback_policy: :caller_runs,
38+
idle_time: 60
39+
)
3340
end
3441

3542
# Upload the +io+ to the +key+ specified to all services. The upload to the primary service is done synchronously
@@ -75,10 +82,12 @@ def each_service(&block)
7582
end
7683

7784
def perform_across_services(method, *args)
78-
# FIXME: Convert to be threaded
79-
each_service.collect do |service|
80-
service.public_send method, *args
85+
tasks = each_service.collect do |service|
86+
Concurrent::Promise.execute(executor: @executor) do
87+
service.public_send method, *args
88+
end
8189
end
90+
tasks.each(&:value!)
8291
end
8392
end
8493
end

0 commit comments

Comments
 (0)