favorites: fix users with incorrect favorite counts.
Fix users that have a non-zero favorite count, but no favorites.
Follow-up to 69facb22b.
This commit is contained in:
@@ -602,6 +602,10 @@ class User < ApplicationRecord
|
|||||||
|
|
||||||
class_methods do
|
class_methods do
|
||||||
def fix_favorite_counts!
|
def fix_favorite_counts!
|
||||||
|
# Fix users that have a non-zero favorite_count but no favorites.
|
||||||
|
User.where("favorite_count != 0").where.not(id: Favorite.select(:user_id).distinct).update_all(favorite_count: 0)
|
||||||
|
|
||||||
|
# Fix users that have a favorite_count inconsistent with the favorites table.
|
||||||
User.find_by_sql(<<~SQL.squish)
|
User.find_by_sql(<<~SQL.squish)
|
||||||
UPDATE users
|
UPDATE users
|
||||||
SET favorite_count = true_count
|
SET favorite_count = true_count
|
||||||
|
|||||||
Reference in New Issue
Block a user