Files
danbooru/app/logical/post_pruner.rb
evazion 3096cea2d6 maintenance: fix db timeouts in regenerate_post_counts!
Disable database timeouts durings daily maintenance. Fixes
`regenerate_post_counts!` timing out. Remove calls to without_timeout
because otherwise it will reenable the timeout when trying to restore
the old timeout (see 97cc873a3f).
2019-10-01 22:51:40 -05:00

40 lines
1000 B
Ruby

class PostPruner
def prune!
prune_pending!
prune_flagged!
prune_mod_actions!
end
protected
def prune_pending!
CurrentUser.scoped(User.system, "127.0.0.1") do
Post.where("is_deleted = ? and is_pending = ? and created_at < ?", false, true, 3.days.ago).each do |post|
begin
post.delete!("Unapproved in three days")
rescue PostFlag::Error
# swallow
end
end
end
end
def prune_flagged!
CurrentUser.scoped(User.system, "127.0.0.1") do
Post.where("is_deleted = ? and is_flagged = ?", false, true).each do |post|
if post.flags.unresolved.old.any?
begin
post.delete!("Unapproved in three days after returning to moderation queue")
rescue PostFlag::Error
# swallow
end
end
end
end
end
def prune_mod_actions!
ModAction.where(["creator_id = ? and description like ?", User.system.id, "deleted post %"]).destroy_all
end
end