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

1 commit

Author SHA1 Message Date
Chris Parsons
623fb1dfc0 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
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>
2026-05-26 21:23:40 -07:00