eBooru/app/logical/post_pruner.rb
Earlopain fc7d84affd
[RuboCop] Enable Style/FrozenStringLiteralComment
This reduces allocations on the posts page by about 5%, from basic testing
2024-02-25 18:15:55 +01:00

24 lines
481 B
Ruby

# frozen_string_literal: true
class PostPruner
DELETION_WINDOW = 30
def prune!
Post.without_timeout do
prune_pending!
end
end
protected
def prune_pending!
CurrentUser.as_system do
Post.where("is_deleted = ? and is_pending = ? and created_at < ?", false, true, DELETION_WINDOW.days.ago).find_each do |post|
post.delete!("Unapproved in #{DELETION_WINDOW} days")
rescue PostFlag::Error
# swallow
end
end
end
end