claude/cool-lamport-etpwsi #96

Merged
chrisp merged 3 commits from claude/cool-lamport-etpwsi into main 2026-06-17 19:46:59 +00:00
Showing only changes of commit 9a04e25c20 - Show all commits

View file

@ -310,33 +310,54 @@ export async function getUpcomingScoringEvents(
if (events.length === 0) return [];
// Find earliest upcoming game time per event from bracket match games.
// Find earliest upcoming game time per event from both bracket match games
// and group stage matches (FIFA World Cup style).
const eventIds = events.map((e) => e.id);
const now = new Date();
const gameTimeRows = await db
.select({
eventId: schema.scoringEvents.id,
scheduledAt: schema.playoffMatchGames.scheduledAt,
})
.from(schema.scoringEvents)
.innerJoin(
schema.playoffMatches,
eq(schema.playoffMatches.scoringEventId, schema.scoringEvents.id)
)
.innerJoin(
schema.playoffMatchGames,
eq(schema.playoffMatchGames.playoffMatchId, schema.playoffMatches.id)
)
.where(
and(
inArray(schema.scoringEvents.id, eventIds),
isNotNull(schema.playoffMatchGames.scheduledAt),
gte(schema.playoffMatchGames.scheduledAt, now)
const [gameTimeRows, groupStageTimeRows] = await Promise.all([
db
.select({
eventId: schema.scoringEvents.id,
scheduledAt: schema.playoffMatchGames.scheduledAt,
})
.from(schema.scoringEvents)
.innerJoin(
schema.playoffMatches,
eq(schema.playoffMatches.scoringEventId, schema.scoringEvents.id)
)
);
.innerJoin(
schema.playoffMatchGames,
eq(schema.playoffMatchGames.playoffMatchId, schema.playoffMatches.id)
)
.where(
and(
inArray(schema.scoringEvents.id, eventIds),
isNotNull(schema.playoffMatchGames.scheduledAt),
gte(schema.playoffMatchGames.scheduledAt, now)
)
),
db
.select({
eventId: schema.tournamentGroups.scoringEventId,
scheduledAt: schema.groupStageMatches.scheduledAt,
})
.from(schema.groupStageMatches)
.innerJoin(
schema.tournamentGroups,
eq(schema.groupStageMatches.tournamentGroupId, schema.tournamentGroups.id)
)
.where(
and(
inArray(schema.tournamentGroups.scoringEventId, eventIds),
isNotNull(schema.groupStageMatches.scheduledAt),
gte(schema.groupStageMatches.scheduledAt, now)
)
),
]);
const earliestGameById = new Map<string, Date>();
for (const row of gameTimeRows) {
for (const row of [...gameTimeRows, ...groupStageTimeRows]) {
if (!row.scheduledAt) continue;
const prev = earliestGameById.get(row.eventId);
if (!prev || row.scheduledAt < prev) {