Polish simulate route after code review

- Remove redundant db variable; use database() inline consistent with
  all other model calls in this file
- Parallelize standings recalculation with Promise.all
- Update file header comment to include the standings refresh step

https://claude.ai/code/session_01S9Pk4wTSphANMhPWaURPTn
This commit is contained in:
Claude 2026-03-20 21:33:47 +00:00
parent e284d08f2b
commit b21c553c9c
No known key found for this signature in database

View file

@ -5,8 +5,9 @@
* 1. Guards against concurrent runs via simulationStatus * 1. Guards against concurrent runs via simulationStatus
* 2. Runs the appropriate simulator based on the sport's simulatorType * 2. Runs the appropriate simulator based on the sport's simulatorType
* 3. Persists updated EVs to participantExpectedValues (transactional) * 3. Persists updated EVs to participantExpectedValues (transactional)
* 4. Takes an EV snapshot from simulation output (upsert for today's date) * 4. Refreshes cached projectedPoints in teamStandings for all affected fantasy seasons
* 5. Redirects back to the sports season admin page * 5. Takes an EV snapshot from simulation output (upsert for today's date)
* 6. Redirects back to the sports season admin page
*/ */
import { redirect } from "react-router"; import { redirect } from "react-router";
@ -104,13 +105,10 @@ export async function action({ params }: Route.ActionArgs) {
await batchUpsertParticipantEVs(evInputs); await batchUpsertParticipantEVs(evInputs);
// Refresh cached projectedPoints in teamStandings for all affected fantasy seasons // Refresh cached projectedPoints in teamStandings for all affected fantasy seasons
const db = database(); const seasonSports = await database().query.seasonSports.findMany({
const seasonSports = await db.query.seasonSports.findMany({
where: eq(schema.seasonSports.sportsSeasonId, sportsSeasonId), where: eq(schema.seasonSports.sportsSeasonId, sportsSeasonId),
}); });
for (const { seasonId } of seasonSports) { await Promise.all(seasonSports.map(({ seasonId }) => recalculateStandings(seasonId)));
await recalculateStandings(seasonId, db);
}
// Take EV snapshot from simulation output (not re-read from DB) // Take EV snapshot from simulation output (not re-read from DB)
const today = new Date().toISOString().slice(0, 10); // YYYY-MM-DD const today = new Date().toISOString().slice(0, 10); // YYYY-MM-DD