diff --git a/app/models/cs2-major-stage.ts b/app/models/cs2-major-stage.ts index 4875178..a04bb38 100644 --- a/app/models/cs2-major-stage.ts +++ b/app/models/cs2-major-stage.ts @@ -14,7 +14,7 @@ import { database } from "~/database/context"; import { cs2MajorStageResults, participants } from "~/database/schema"; -import { eq, inArray, sql } from "drizzle-orm"; +import { eq, and, inArray, sql } from "drizzle-orm"; export interface Cs2StageResult { id: string; @@ -157,10 +157,10 @@ export async function markCs2StageEliminations( stageEliminatedWins: winsAtElimination, updatedAt: now, }) - .where( - eq(cs2MajorStageResults.scoringEventId, scoringEventId) && + .where(and( + eq(cs2MajorStageResults.scoringEventId, scoringEventId), eq(cs2MajorStageResults.participantId, participantId) - ) + )) ) ); } @@ -184,10 +184,10 @@ export async function setCs2FinalPlacements( db .update(cs2MajorStageResults) .set({ finalPlacement: placements[participantId], updatedAt: now }) - .where( - eq(cs2MajorStageResults.scoringEventId, scoringEventId) && + .where(and( + eq(cs2MajorStageResults.scoringEventId, scoringEventId), eq(cs2MajorStageResults.participantId, participantId) - ) + )) ) ); } diff --git a/app/services/simulations/cs-major-simulator.ts b/app/services/simulations/cs-major-simulator.ts index 351baf7..31859a8 100644 --- a/app/services/simulations/cs-major-simulator.ts +++ b/app/services/simulations/cs-major-simulator.ts @@ -193,6 +193,10 @@ export function simulateSwiss(teams: TeamWithElo[], bo3: boolean): SwissResult { // (simplified: skip teams that can't be paired — they sit out this round) const pairs = pairGroups(groups); + // Safety: if no pairs can be formed (shouldn't happen with even team counts + // but guards against an infinite loop if an odd active count somehow occurs) + if (pairs.length === 0) break; + for (const [t1, t2] of pairs) { const e1 = eloMap.get(t1.id) ?? FALLBACK_ELO; const e2 = eloMap.get(t2.id) ?? FALLBACK_ELO;