potential fix for #1305

This commit is contained in:
Albert Yi
2013-04-14 18:22:25 -07:00
parent 96a468b51a
commit f5b0f856d6
4 changed files with 21 additions and 14 deletions

View File

@@ -1,18 +1,21 @@
class ApiCacheGenerator
def generate_tag_cache
File.open("#{Rails.root}/public/cache/tags.json", "w") do |f|
FileUtils.mkdir_p("/var/www/danbooru2/shared/system/cache")
File.open("/var/www/danbooru2/shared/system/cache/tags.json", "w") do |f|
f.print("[")
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(", ")
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")

View File

@@ -2,7 +2,7 @@ class DailyMaintenance
def run
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
PostPruner.new.prune!
# TagPruner.new.prune!
TagPruner.new.prune!
Upload.delete_all(['created_at < ?', 1.day.ago])
ModAction.delete_all(['created_at < ?', 3.days.ago])
Delayed::Job.delete_all(['created_at < ?', 1.day.ago])

View File

@@ -1,7 +1,6 @@
class TagPruner
def prune!
Tag.without_timeout do
Tag.destroy_all(["post_count <= 0 and name like '%%:%%'"])
end
end
end

View File

@@ -57,6 +57,11 @@ namespace :data do
run "rm -f #{release_path}/public/images/advertisements"
run "ln -s #{deploy_to}/shared/advertisements #{release_path}/public/images/advertisements"
run "mkdir -p #{release_path}/public/cache"
run "mkdir -p #{deploy_to}/shared/system/cache"
run "touch #{deploy_to}/shared/system/cache/tags.json"
run "ln -s #{deploy_to}/shared/system/cache/tags.json #{release_path}/public/cache/tags.json"
end
end