Fix slow bracket save and stale projected points #54

Merged
chrisp merged 1 commit from fix/bracket-save-projected-points into main 2026-05-27 04:28:11 +00:00
Owner

Summary

  • Swap side-effect order so updateProbabilitiesAfterResult runs before recalculateAffectedLeagues in processMatchResult, processPlayoffEvent, and the set-round-winners route — projected points now reflect the new result immediately instead of waiting on the next simulation.
  • Eliminate the N+1 EV lookup in calculateTeamProjectedScore by pre-fetching every EV the season needs in a single inArray query inside recalculateStandings and passing the map down.
  • Add skipProbabilities option to processPlayoffEvent, used from autoCompleteRoundIfDone (callers have already refreshed EVs), avoiding a redundant pass on round-completing saves.

Fixes #31

Test plan

  • npm run typecheck
  • npx vitest run app/models/__tests__/team-projected-score.test.ts app/models/__tests__/process-match-result.test.ts app/services/__tests__/probability-updater.test.ts — 57/57 passing
  • Manual: save a round of bracket winners on a sports season with at least one fantasy league and confirm (a) the request returns faster and (b) the team standings show projected points updated to reflect the result without re-running the simulator

🤖 Generated with Claude Code

## Summary - Swap side-effect order so `updateProbabilitiesAfterResult` runs before `recalculateAffectedLeagues` in `processMatchResult`, `processPlayoffEvent`, and the `set-round-winners` route — projected points now reflect the new result immediately instead of waiting on the next simulation. - Eliminate the N+1 EV lookup in `calculateTeamProjectedScore` by pre-fetching every EV the season needs in a single `inArray` query inside `recalculateStandings` and passing the map down. - Add `skipProbabilities` option to `processPlayoffEvent`, used from `autoCompleteRoundIfDone` (callers have already refreshed EVs), avoiding a redundant pass on round-completing saves. Fixes #31 ## Test plan - [x] `npm run typecheck` - [x] `npx vitest run app/models/__tests__/team-projected-score.test.ts app/models/__tests__/process-match-result.test.ts app/services/__tests__/probability-updater.test.ts` — 57/57 passing - [ ] Manual: save a round of bracket winners on a sports season with at least one fantasy league and confirm (a) the request returns faster and (b) the team standings show projected points updated to reflect the result without re-running the simulator 🤖 Generated with [Claude Code](https://claude.com/claude-code)
chrisp added 1 commit 2026-05-27 04:23:56 +00:00
Fix slow bracket save and stale projected points
All checks were successful
🚀 Deploy / 🧪 Test (pull_request) Successful in 1m35s
🚀 Deploy / ʦ TypeScript (pull_request) Successful in 1m20s
🚀 Deploy / 🔍 Lint (pull_request) Successful in 49s
🚀 Deploy / 🐳 Build (pull_request) Has been skipped
🚀 Deploy / 🚀 Deploy (pull_request) Has been skipped
623fb1dfc0
Saving a bracket result was slow and left the projected-points column
showing pre-result EVs until the next simulation.

Root causes:
- Side effects ran in the wrong order: recalculateAffectedLeagues
  (which reads EVs to compute projected points) fired before
  updateProbabilitiesAfterResult wrote the new EVs.
- calculateTeamProjectedScore issued one getParticipantEV query per
  unfinished pick, multiplied by every team in every affected league.

Changes:
- Swap side-effect order in processMatchResult, processPlayoffEvent,
  and the set-round-winners route so probabilities update first.
- Pre-fetch every EV referenced by a season's draft picks in a single
  inArray query inside recalculateStandings and pass the map down to
  calculateTeamProjectedScore (with a getParticipantEV fallback).
- Add skipProbabilities option to processPlayoffEvent and use it from
  autoCompleteRoundIfDone, where the caller has already refreshed EVs.

Fixes #31

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
chrisp merged commit a02f603575 into main 2026-05-27 04:28:11 +00:00
chrisp deleted branch fix/bracket-save-projected-points 2026-05-27 04:28:11 +00:00
Sign in to join this conversation.
No description provided.