favorites: delete favorites for expunged posts.

Delete favorites that have an invalid post_id because they belong to an
expunged post.

This bug of not deleting favorites after a post is expunged was fixed
long ago, but old favorites were never cleaned up.

Fixes #4711: Some users have incorrect fav count.
This commit is contained in:
evazion
2022-01-08 20:55:55 -06:00
parent 04d3a04836
commit 3814aa21b3

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env ruby
require_relative "../../config/environment"
Favorite.transaction do
Favorite.left_outer_joins(:post).where("posts.id": nil).destroy_all
print "Commit? (yes/no): "
raise "abort" unless STDIN.readline.chomp == "yes"
end