From e284d08f2bf642e8eb11d2d9406f5778430262a4 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Mar 2026 21:31:21 +0000 Subject: [PATCH] Use recalculateStandings directly after EV simulation Replaces recalculateAffectedLeagues (which carries Discord notification and daily snapshot side effects) with a direct call to recalculateStandings per affected fantasy season. This updates the cached projectedPoints in teamStandings so the standings page stays in sync with the team page after a simulation, without triggering unrelated side effects. https://claude.ai/code/session_01S9Pk4wTSphANMhPWaURPTn --- app/routes/admin.sports-seasons.$id.simulate.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/routes/admin.sports-seasons.$id.simulate.tsx b/app/routes/admin.sports-seasons.$id.simulate.tsx index 6a37a2e..e44c965 100644 --- a/app/routes/admin.sports-seasons.$id.simulate.tsx +++ b/app/routes/admin.sports-seasons.$id.simulate.tsx @@ -17,7 +17,10 @@ import { batchUpsertParticipantEvSnapshots } from "~/models/ev-snapshot"; import { findParticipantsBySportsSeasonId } from "~/models/participant"; import { getSimulator, type SimulatorType } from "~/services/simulations/registry"; import { calculateEV, type ScoringRules } from "~/services/ev-calculator"; -import { recalculateAffectedLeagues } from "~/models/scoring-calculator"; +import { recalculateStandings } from "~/models/scoring-calculator"; +import { database } from "~/database/context"; +import * as schema from "~/database/schema"; +import { eq } from "drizzle-orm"; // Default scoring rules — matches the season table defaults. // Per-league EV is recalculated from probabilities using league-specific rules in standings. @@ -100,8 +103,14 @@ export async function action({ params }: Route.ActionArgs) { // Persist updated EVs (transactional) await batchUpsertParticipantEVs(evInputs); - // Force standings recalculation so projectedPoints reflects the new EV - await recalculateAffectedLeagues(sportsSeasonId); + // Refresh cached projectedPoints in teamStandings for all affected fantasy seasons + const db = database(); + const seasonSports = await db.query.seasonSports.findMany({ + where: eq(schema.seasonSports.sportsSeasonId, sportsSeasonId), + }); + for (const { seasonId } of seasonSports) { + await recalculateStandings(seasonId, db); + } // Take EV snapshot from simulation output (not re-read from DB) const today = new Date().toISOString().slice(0, 10); // YYYY-MM-DD