DEV: ensure rebaking works even when some users have inconsistent data (#30261)

* DEV: add db consistency check for UserEmail

* DEV: add db consistency check for UserAvatar

* DEV: ignore inconsistent data related to user avatars when deciding whether to rebake old posts


Co-authored-by: Alan Guo Xiang Tan <gxtan1990@gmail.com>

---------

Co-authored-by: Alan Guo Xiang Tan <gxtan1990@gmail.com>
This commit is contained in:
Kelv
2024-12-16 19:48:25 +08:00
committed by GitHub
parent ce8c2ef6d9
commit 04ba5baec0
7 changed files with 118 additions and 2 deletions

View File

@@ -152,6 +152,13 @@ class UserAvatar < ActiveRecord::Base
end
def self.ensure_consistency!(max_optimized_avatars_to_remove: 20_000)
DB.exec <<~SQL
DELETE FROM user_avatars
USING user_avatars ua
LEFT JOIN users u ON ua.user_id = u.id
WHERE user_avatars.id = ua.id AND u.id IS NULL
SQL
DB.exec <<~SQL
UPDATE user_avatars
SET gravatar_upload_id = NULL