如何批量删除旧的私语

这是删除帖子的最简洁方式:

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

这实际上相当于系统用户手动点击帖子上的删除按钮来删除每个帖子。我加入了 skip_staff_log,以免污染您的员工日志,但如果您希望记录该操作,可以将其移除。

您觉得这样可以满足您的需求吗?