From 3814aa21b3e472e3240e89a3e1f545bbe30496e6 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 8 Jan 2022 20:55:55 -0600 Subject: [PATCH] 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. --- script/fixes/085_fix_invalid_favorites.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 script/fixes/085_fix_invalid_favorites.rb diff --git a/script/fixes/085_fix_invalid_favorites.rb b/script/fixes/085_fix_invalid_favorites.rb new file mode 100755 index 000000000..5f5a0e3b0 --- /dev/null +++ b/script/fixes/085_fix_invalid_favorites.rb @@ -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