storage manager: remove 'hybrid' and 'match' manager.
Remove StorageManager::Hybrid and StorageManager::Match. These were used to store uploads on different servers based on the post ID or file sample type. This is no longer used in production because in hindsight it's a lot more difficult to manage uploads when they're fragmented across different servers. If you need this, you can do tricks with network filesystems to get the same effect. For example, if you want to store some files on server A and others on server B, then mount servers A and B as network filesystems (with e.g. sshfs, Samba, NFS, etc), and use symlinks to point subdirectories at either server A or B.
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
class StorageManager::Hybrid < StorageManager
|
||||
attr_reader :submanager
|
||||
|
||||
def initialize(&block)
|
||||
@submanager = block
|
||||
end
|
||||
|
||||
def store_file(io, post, type)
|
||||
submanager[post.id, post.md5, post.file_ext, type].store_file(io, post, type)
|
||||
end
|
||||
|
||||
def delete_file(post_id, md5, file_ext, type)
|
||||
submanager[post_id, md5, file_ext, type].delete_file(post_id, md5, file_ext, type)
|
||||
end
|
||||
|
||||
def open_file(post, type)
|
||||
submanager[post.id, post.md5, post.file_ext, type].open_file(post, type)
|
||||
end
|
||||
|
||||
def file_url(post, type, **options)
|
||||
submanager[post.id, post.md5, post.file_ext, type].file_url(post, type, **options)
|
||||
end
|
||||
end
|
||||
@@ -1,109 +0,0 @@
|
||||
#
|
||||
# Generalizes the hybrid storage manager to be more declarative in
|
||||
# syntax. Matches are executed in order of appearance so the first
|
||||
# matching manager is returned. You should always add at least one
|
||||
# manager with no constraints as a default case.
|
||||
#
|
||||
### Example
|
||||
#
|
||||
# StorageManager::Match.new do |matcher|
|
||||
# matcher.add_manager(type: :crop) do
|
||||
# StorageManager::SFTP.new("raikou3.donmai.us", base_url: "https://raikou3.donmai.us", base_dir: "/var/www/raikou3")
|
||||
# end
|
||||
#
|
||||
# matcher.add_manager(id: 1..850_000) do
|
||||
# StorageManager::SFTP.new("raikou1.donmai.us", base_url: "https://raikou1.donmai.us", base_dir: "/var/www/raikou1")
|
||||
# end
|
||||
#
|
||||
# matcher.add_manager(id: 850_001..2_000_000) do
|
||||
# StorageManager::SFTP.new("raikou2.donmai.us", base_url: "https://raikou2.donmai.us", base_dir: "/var/www/raikou2")
|
||||
# end
|
||||
#
|
||||
# matcher.add_manager(id: 1..3_000_000, type: [:large, :original]) do
|
||||
# StorageManager::SFTP.new(*Danbooru.config.all_server_hosts, base_url: "https://hijiribe.donmai.us/data")
|
||||
# end
|
||||
#
|
||||
# matcher.add_manager({}) do
|
||||
# StorageManager::SFTP.new(*Danbooru.config.all_server_hosts, base_url: "#{CurrentUser.root_url}/data")
|
||||
# end
|
||||
# end
|
||||
#
|
||||
|
||||
class StorageManager::Match < StorageManager
|
||||
def initialize
|
||||
@managers = []
|
||||
|
||||
yield self if block_given?
|
||||
end
|
||||
|
||||
def add_manager(constraints)
|
||||
manager = yield
|
||||
@managers << [constraints, manager]
|
||||
end
|
||||
|
||||
def find(params)
|
||||
@managers.each do |constraints, manager|
|
||||
match = true
|
||||
|
||||
if params[:id] && constraints[:id] && !constraints[:id].include?(params[:id].to_i)
|
||||
match = false
|
||||
end
|
||||
|
||||
if constraints[:id] && !params[:id]
|
||||
match = false
|
||||
end
|
||||
|
||||
if params[:type] && constraints[:type]
|
||||
if constraints[:type].respond_to?(:include?)
|
||||
if !constraints[:type].include?(params[:type])
|
||||
match = false
|
||||
end
|
||||
elsif constraints[:type] != params[:type]
|
||||
match = false
|
||||
end
|
||||
end
|
||||
|
||||
if constraints[:type] && !params[:type]
|
||||
match = false
|
||||
end
|
||||
|
||||
if match
|
||||
if block_given?
|
||||
return yield(manager)
|
||||
else
|
||||
return manager
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def store_file(io, post, type)
|
||||
find(id: post.id, type: type) do |manager|
|
||||
manager.store_file(io, post, type)
|
||||
end
|
||||
end
|
||||
|
||||
def delete_file(post_id, md5, file_ext, type)
|
||||
find(id: post_id, type: type) do |manager|
|
||||
manager.delete_file(post_id, md5, file_ext, type)
|
||||
end
|
||||
end
|
||||
|
||||
def open_file(post, type)
|
||||
find(id: post.id, type: type) do |manager|
|
||||
manager.open_file(post, type)
|
||||
end
|
||||
end
|
||||
|
||||
def file_url(post, type, **options)
|
||||
find(id: post.id, type: type) do |manager|
|
||||
manager.file_url(post, type, **options)
|
||||
end
|
||||
end
|
||||
|
||||
def file_path(post, file_ext, type, **options)
|
||||
find(id: post.id, type: type) do |manager|
|
||||
manager.file_path(post, file_ext, type, **options)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user