Skip to content

fix: correct two regressions from code-review fixes#25

Merged
daimpad merged 1 commit into
mainfrom
fix/review-followup
Jun 4, 2026
Merged

fix: correct two regressions from code-review fixes#25
daimpad merged 1 commit into
mainfrom
fix/review-followup

Conversation

@daimpad

@daimpad daimpad commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Summary

Two regressions introduced in PR #23 that were caught by a follow-up code review.

removeMatch — stale ELOs for uninvolved players

The previous fix changed removeMatch to only write back the 2–4 players directly in the deleted match. But recalculateStatsFromHistory() replays all matches from scratch — any player who faced A or B in a later match also gets a new ELO via chain reaction. Those players were never written back to Supabase, leaving their DB records stale. Reverted to writing all players.

saveMatch — partial DB write not reverted on failure

updatePlayer calls run sequentially before createMatch. If createMatch (or a later updatePlayer) throws, the catch block rolls back local state correctly — but any Supabase player rows already written retain the inflated ELOs. Added a compensating Promise.all in the catch block that re-writes those players back to their post-rollback (correct) ELOs.

Test plan

  • All 56 tests pass (npm test)
  • Delete a match in a multi-match history — verify all player ELOs update correctly in Supabase, not just the two participants
  • Simulate a failed save (e.g. wrong APP_SECRET) — verify no ELO values are left inflated in Supabase

https://claude.ai/code/session_01TgxiTLy7fCh5xZPJT8eTVt


Generated by Claude Code

- removeMatch: revert targeted-write optimisation — recalculateStatsFromHistory
  replays all matches, so all players' ELOs can change via chain reaction;
  writing only the 2-4 participants left every other player stale in Supabase
- saveMatch: add DB revert in the catch block — if updatePlayer succeeds for
  some players but createMatch then throws, the already-written Supabase rows
  are now corrected back to the post-rollback ELOs so DB stays consistent

https://claude.ai/code/session_01TgxiTLy7fCh5xZPJT8eTVt
@daimpad daimpad merged commit 51e6e04 into main Jun 4, 2026
1 check passed
@daimpad daimpad deleted the fix/review-followup branch June 4, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants