How to bulk delete old whispers

This would be the cleanest way to delete the posts:

whispers = Post.where(post_type: 4).where("created_at < ?", 1.year.ago)

whispers.find_each do |w|
  PostDestroyer.new(Discourse.system_user, w, skip_staff_log: true).destroy
  putc "."
end

This will essentially act as if the System user deleted each post by hand using the delete button on the post. I included skip_staff_log so you don’t pollute your staff logs, but you can remove that if you’d prefer to have the action logged.

Do you think that will meet your needs?

4 Likes