class TopicCleaner
def self.delete_small_actions(topic_id, dry_run: false)
topic = Topic.find_by(id: topic_id)
unless topic
puts "Topic #{topic_id} not found"
return
end
posts = topic.posts.where(post_type: Post.types[:small_action])
to_delete = posts.select { |p| p.raw.strip.downcase == "delete" }
if to_delete.empty?
puts "No small action posts with 'delete' found in topic #{topic_id}"
return
end
puts "Found #{to_delete.size} matching posts in topic ##{topic_id}"
to_delete.each do |post|
if dry_run
puts "Would PERMANENTLY delete post ##{post.id} (created #{post.created_at}, by #{post.user.username})"
else
post.destroy()
puts "🗑️ Permanently deleted post ##{post.id}"
end
end
puts dry_run ? "Dry run complete — no posts deleted." : "Finished permanent cleanup of topic #{topic_id}"
end
end