Repository navigation
fix(account): evict leaderboard and profile caches on account deletion - #3647
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
Deleting an account removed every row through the delete_app_user transaction but left the cached copies of that user's public data in place. The leaderboard is cached in process memory, in Redis/Upstash and in the Next.js data cache (refreshed every 3 hours), and the public profile under its public-profile:<login> tag (2 hours), so a deleted user kept their spot on the board and their /u/<login> page stayed viewable until those caches expired. After a successful deletion, DELETE /api/user/data-export now: - calls clearLeaderboardCache(), the same eviction the settings route runs when someone leaves the board, so the next request rebuilds the board without them; - calls invalidatePublicProfile() for the session login, which also drops the cached "is this login registered" check, so the profile page falls back to the guest view straight away. Both run only once the transaction has succeeded. The account is already gone at that point, so an eviction failure is logged and the request still returns success and clears the session cookies. Tests cover the eviction after a successful delete, that nothing is evicted when the request is unauthenticated or the deletion fails or finds no user, and that eviction errors do not turn a completed deletion into an error response. Closes Priyanshu-byte-coder#934
officialasishkumar
requested a review
from Priyanshu-byte-coder
as a code owner
November 19, 2026 21:46
This branch has not been deployed
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.
Summary
Deleting an account removed every row in the
delete_app_usertransaction but left that user's cached public data in place. The leaderboard (process memory, Redis/Upstash and the Next.js data cache, refreshed every 3 hours) kept listing them, and their/u/<login>page stayed viewable from the 2-hour profile cache. After a successful deletion,DELETE /api/user/data-exportnow evicts both, the same way the settings route already does when someone leaves the board or makes their profile private.Closes #934
Type of Change
What Changed
src/app/api/user/data-export/route.ts(DELETE): once the transaction has succeeded:clearLeaderboardCache()drops all three leaderboard layers, so the next request rebuilds the board without the deleted user.invalidatePublicProfile(session.githubLogin)expires thepublic-profile:<login>tag. That tag covers the member profile data, the duel data and the cached "is this login registered" check, so/u/<login>falls back to the guest view straight away.test/account-deletion.test.ts: mocks both helpers and checks that they run after the RPC on a successful delete, don't run on the 401/503/404 paths, and that a Redis error or arevalidateTagthrow doesn't turn a completed deletion into an error. The two new tests fail onmain.How to Test
pnpm vitest run test/account-deletion.test.ts test/data-export.test.ts test/leaderboard-cache-invalidation.test.ts/leaderboardand/u/<login>so both are cached./leaderboardand/u/<login>.Expected result: The deleted user is gone from the leaderboard and their profile shows the guest view at once, not hours later when the caches expire.
Checklist
console.log, debug code, or commented-out blocksnpm run lintpasses locallynpm run type-check)Additional Context
GoalTracker, so the deletion route never evicted anything.user_progress, rank snapshots) are keyed by user ids taken from the leaderboard and cascade-deleted with the user, so once the board rebuilds they no longer reference the deleted account.tsc --noEmit, ESLint and Prettier pass on the changed files, along with the three test files above.