How to bulk delete old whispers

Continuing the discussion from Administrative Bulk Operations:

I’m looking for a way to delete whispers over a certain age from all topics.

Generally we use whispers to discuss potential moderator actions, but once action had been taken, the whispers aren’t so useful and increasingly become noise as time passes.

I could delete posts over a certain age with post_type=4 (whisper) but this seems like could leave things dangling or inconsistent in the database, or not be allowed due to forum keys.

It’s there a safe way to do this?

2 Likes

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

I think that looks perfect - thank you!

I’ll give it a go on a test instance, and see how long it takes as we probably have a few thousand whispers!!!

2 Likes

So this task works well, thank you… but the whispers are simply collapsed and still viewable by Admins and moderators when expanded.

This does tidy up topics, but I was hoping they could be completely removed in their entirety. I wondered if the whispers could all be moved to a new topic, and that then deleted or hidden from mods at least, but then I found this: Is there a way to remove all the deleted/hidden posts? And more recently: Why is it not possible to permanently delete topics or posts?

Unfortunately the above suggest there is no way to permanently remove the data :frowning: