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
This commit is contained in:
Claude 2026-03-20 21:31:21 +00:00
parent 7cf37aace8
commit e284d08f2b
No known key found for this signature in database

View file

@ -17,7 +17,10 @@ import { batchUpsertParticipantEvSnapshots } from "~/models/ev-snapshot";
import { findParticipantsBySportsSeasonId } from "~/models/participant"; import { findParticipantsBySportsSeasonId } from "~/models/participant";
import { getSimulator, type SimulatorType } from "~/services/simulations/registry"; import { getSimulator, type SimulatorType } from "~/services/simulations/registry";
import { calculateEV, type ScoringRules } from "~/services/ev-calculator"; 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. // Default scoring rules — matches the season table defaults.
// Per-league EV is recalculated from probabilities using league-specific rules in standings. // 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) // Persist updated EVs (transactional)
await batchUpsertParticipantEVs(evInputs); await batchUpsertParticipantEVs(evInputs);
// Force standings recalculation so projectedPoints reflects the new EV // Refresh cached projectedPoints in teamStandings for all affected fantasy seasons
await recalculateAffectedLeagues(sportsSeasonId); 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) // 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