Discourse: Bulk Permanently Delete Deleted Topics and Replies

By default, Discourse is not designed to allow bulk permanent deletion of topics, but we can easily accomplish this via the Rails console, with the relevant commands as follows:

./launcher enter app
rails c

Topic.with_deleted.where(deleted_at: ...1.seconds.ago).limit(1000).destroy_all
Post.find_by_sql("select * from posts where topic_id not in (select id from topics)").each { |p| p.destroy }

If you also want to permanently delete deleted replies to topics, you can use this command:

Post.with_deleted.where(deleted_at: ...1.seconds.ago).limit(1000).destroy_all