批量永久删除已删除的帖子?

为了删除我们论坛上的旧帖子,我使用了以下方法。这是结合了 The proper way to completely delete hundred of topics via rails?@RGJ 的建议后得出的结果。

我最终选择这样做,是因为我非常希望从数据库中彻底删除数据,以保护用户隐私。将文本重写为“此帖子已被删除”仍然会保留编辑历史,且相对容易访问,因此不够彻底。

由于我们有 20,000 个主题需要删除,所以花费了一些时间!

Topic.with_deleted.where("deleted_at < '2021-08-28'").limit(1000).destroy_all

由于这留下了大量孤立帖子,我随后必须执行以下操作:

Post.where('topic_id not in (select id from topics)').limit(1000).destroy_all
4 个赞