Drop support for /cache/tag.json.
Drop support for https://danbooru.donmai.us/cache/tags.json. This was a nightly dump of the tags table that was originally added in #1012. It was never documented and never really used except for by the DanbooruUp extension.
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
# donmai.us specific
|
||||
|
||||
class ApiCacheGenerator
|
||||
def generate_tag_cache
|
||||
path = Danbooru.config.shared_dir_path
|
||||
FileUtils.mkdir_p("#{path}/system/cache")
|
||||
File.open("#{path}/system/cache/tags.json", "w") do |f|
|
||||
f.print("[")
|
||||
Tag.without_timeout do
|
||||
Tag.find_each do |tag|
|
||||
next unless tag.post_count > 0
|
||||
hash = {
|
||||
"name" => tag.name,
|
||||
"id" => tag.id,
|
||||
"created_at" => tag.created_at,
|
||||
"post_count" => tag.post_count,
|
||||
"category" => tag.category
|
||||
}
|
||||
f.print(hash.to_json)
|
||||
f.print(", ")
|
||||
end
|
||||
end
|
||||
f.seek(-2, IO::SEEK_END)
|
||||
f.print("]\n")
|
||||
end
|
||||
Zlib::GzipWriter.open("#{path}/system/cache/tags.json.gz") do |gz|
|
||||
gz.write(IO.binread("#{path}/system/cache/tags.json"))
|
||||
gz.close
|
||||
end
|
||||
RemoteFileManager.new("#{path}/system/cache/tags.json").distribute
|
||||
RemoteFileManager.new("#{path}/system/cache/tags.json.gz").distribute
|
||||
end
|
||||
end
|
||||
@@ -13,7 +13,6 @@ module DanbooruMaintenance
|
||||
Delayed::Job.where('created_at < ?', 45.days.ago).delete_all
|
||||
PostVote.prune!
|
||||
CommentVote.prune!
|
||||
ApiCacheGenerator.new.generate_tag_cache
|
||||
PostDisapproval.prune!
|
||||
ForumSubscription.process_all!
|
||||
TagAlias.update_cached_post_counts_for_all
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
require 'securerandom'
|
||||
|
||||
class RemoteFileManager
|
||||
attr_reader :path
|
||||
|
||||
def initialize(path)
|
||||
@path = path
|
||||
end
|
||||
|
||||
def distribute_to_archive(dest_url)
|
||||
uri = URI.parse(dest_url)
|
||||
dir_name = uri.host.split(".").first
|
||||
uuid = SecureRandom.uuid
|
||||
dest_path = "/var/www/#{dir_name}#{uri.path}"
|
||||
temp_path = "/tmp/rfm-#{Danbooru.config.server_host}-#{uuid}"
|
||||
|
||||
Net::SFTP.start(uri.host, Danbooru.config.archive_server_login) do |ftp|
|
||||
ftp.upload!(path, temp_path)
|
||||
begin
|
||||
ftp.rename!(temp_path, dest_path)
|
||||
rescue Net::SFTP::StatusException
|
||||
ftp.remove!(dest_path)
|
||||
ftp.rename!(temp_apth, dest_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def distribute
|
||||
uuid = SecureRandom.uuid
|
||||
temp_path = "/tmp/rfm-#{Danbooru.config.server_host}-#{uuid}"
|
||||
|
||||
Danbooru.config.other_server_hosts.each do |hostname|
|
||||
Net::SFTP.start(hostname, Danbooru.config.remote_server_login) do |ftp|
|
||||
ftp.upload!(path, temp_path)
|
||||
begin
|
||||
ftp.rename!(temp_path, path)
|
||||
rescue Net::SFTP::StatusException
|
||||
# this typically means the file already exists
|
||||
# so delete and try renaming again
|
||||
ftp.remove!(path)
|
||||
ftp.rename!(temp_path, path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
Danbooru.config.other_server_hosts.each do |hostname|
|
||||
Net::SFTP.start(hostname, Danbooru.config.remote_server_login) do |ftp|
|
||||
ftp.remove(path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user