Skip to content

fix(account): evict leaderboard and profile caches on account deletion - #3647

Open
officialasishkumar wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
officialasishkumar:fix/leaderboard-evict-deleted-account
Open

officialasishkumar wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
officialasishkumar:fix/leaderboard-evict-deleted-account

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Summary

Deleting an account removed every row in the delete_app_user transaction 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-export now 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

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 📝 Documentation update
  • ♻️ Refactor / code cleanup (no functional change)
  • ⚡ Performance improvement
  • 🔒 Security fix
  • 🧪 Tests only

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 the public-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.
    • Both are best-effort, as in the settings route: the account is already gone, so a cache failure is logged and the response still reports success and clears the session cookies. Nothing is evicted when the request is unauthenticated, unconfirmed, fails in the database or finds no user.
  • 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 a revalidateTag throw doesn't turn a completed deletion into an error. The two new tests fail on main.

How to Test

  1. pnpm vitest run test/account-deletion.test.ts test/data-export.test.ts test/leaderboard-cache-invalidation.test.ts
  2. With a local Supabase, sign in with an account that's on the leaderboard and open /leaderboard and /u/<login> so both are cached.
  3. Delete the account from Settings, then reload /leaderboard and /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

  • Linked the related issue above
  • Self-reviewed my own diff
  • No unnecessary console.log, debug code, or commented-out blocks
  • npm run lint passes locally
  • No TypeScript errors (npm run type-check)
  • Added or updated tests where applicable
  • Updated documentation / comments if behavior changed

Additional Context

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
@github-actions github-actions Bot added type:bug GSSoC type bonus: bug fix type:testing GSSoC type bonus: tests (+10 pts) labels Nov 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug GSSoC type bonus: bug fix type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Leaderboard cache never evicts entries for users who delete their account

1 participant