Files
danbooru/app/logical/storage_manager/mirror.rb
evazion e7744cb6e3 uploads: generate thumbnails in parallel.
Make uploads faster by generating and saving thumbnails in parallel.

We generate each thumbnail in parallel, then send each thumbnail to the
backend image servers in parallel.

Most images have 5 variants: 'preview' (150x150), 180x180, 360x360,
720x720, and 'sample' (850px width). Plus the original file, that's 6
files we have to save. In production we have 2 image servers, so we have
to save each file twice, to 2 remote servers. Doing all this in parallel
should make uploads significantly faster.
2022-02-04 16:20:50 -06:00

32 lines
674 B
Ruby

# frozen_string_literal: true
# A StorageManager that mirrors files across multiple storage backends.
class StorageManager::Mirror < StorageManager
attr_reader :services
def initialize(services, **options)
@services = services
super(**options)
end
def store(src_file, dest_path)
Parallel.each(services, in_threads: Etc.nprocessors) do |service|
service.store(src_file, dest_path)
end
end
def delete(path)
Parallel.each(services, in_threads: Etc.nprocessors) do |service|
service.delete(path)
end
end
def open(path)
services.first.open(path)
end
def file_url(path)
services.first.file_url(path)
end
end