Fix 'Last post' property of threads not correctly re-set after spammers get deleted#2166
Merged
Conversation
Contributor
Author
Member
|
Thanks a lot for the PR, I reviewed and looks good. I'll merge! |
Contributor
Author
|
Thank you so much! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue(s)
#1575
Description
Fix "Last post" not re-set after spammers get deleted (#1575)
Problem
When a spammer is deleted from the DB, their posts are cascade-deleted along
with their account. This left threads and forums with a blank "last post" and
an inflated reply count on the forum listing pages.
Root cause: the
post_deletesignal handler that repairs these cachedfields tried to update the spammer's own profile first. Since the profile was
already deleted in the cascade, that line raised
Profile.DoesNotExist, whichwas silently caught, so the code never reached the part that re-points
last_postand fixesnum_posts.Changes
1. Fix the signal handler (
forum/models.py)update()so it's a no-op(instead of an exception) when the profile is already gone. The thread/forum
repairs now always run.
num_postsdecrements withGreatest(..., 0)so deletions can'tcrash on counts that are already out of sync.
except Profile.DoesNotExistbranch.user.delete()andProfile.delete_user(delete_user_object_from_db=True)).2. Repair already-broken data (
update_last_thread_forum_postscommand)The fix above only prevents new corruption; rows already broken on production
stay broken. This extends the existing repair command to also recompute
num_posts(previously it only fixedlast_post), and to scan all threads andforums rather than only those with a null
last_post. Run it once afterdeploying to heal the historical data.
Testing
forum/andaccounts/tests/test_user.pysuites pass.ran the command, confirmed
last_postandnum_postswere restored.Deployment steps:
After deploying, run the forum repair command once to fix threads/forums whose
last_post/num_postswere already corrupted by this bug before the fix:(Run with
--dryfirst to see how many rows would change without writing.)