From b21c553c9c4dc52b4209298b8153194dcdb4e96a Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Mar 2026 21:33:47 +0000 Subject: [PATCH] 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 --- app/routes/admin.sports-seasons.$id.simulate.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/routes/admin.sports-seasons.$id.simulate.tsx b/app/routes/admin.sports-seasons.$id.simulate.tsx index e44c965..5fc9bc2 100644 --- a/app/routes/admin.sports-seasons.$id.simulate.tsx +++ b/app/routes/admin.sports-seasons.$id.simulate.tsx @@ -5,8 +5,9 @@ * 1. Guards against concurrent runs via simulationStatus * 2. Runs the appropriate simulator based on the sport's simulatorType * 3. Persists updated EVs to participantExpectedValues (transactional) - * 4. Takes an EV snapshot from simulation output (upsert for today's date) - * 5. Redirects back to the sports season admin page + * 4. Refreshes cached projectedPoints in teamStandings for all affected fantasy seasons + * 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"; @@ -104,13 +105,10 @@ export async function action({ params }: Route.ActionArgs) { await batchUpsertParticipantEVs(evInputs); // Refresh cached projectedPoints in teamStandings for all affected fantasy seasons - const db = database(); - const seasonSports = await db.query.seasonSports.findMany({ + const seasonSports = await database().query.seasonSports.findMany({ where: eq(schema.seasonSports.sportsSeasonId, sportsSeasonId), }); - for (const { seasonId } of seasonSports) { - await recalculateStandings(seasonId, db); - } + await Promise.all(seasonSports.map(({ seasonId }) => recalculateStandings(seasonId))); // Take EV snapshot from simulation output (not re-read from DB) const today = new Date().toISOString().slice(0, 10); // YYYY-MM-DD