claude/cool-lamport-etpwsi #96
1 changed files with 43 additions and 22 deletions
|
|
@ -310,33 +310,54 @@ export async function getUpcomingScoringEvents(
|
||||||
|
|
||||||
if (events.length === 0) return [];
|
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 eventIds = events.map((e) => e.id);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const gameTimeRows = await db
|
|
||||||
.select({
|
const [gameTimeRows, groupStageTimeRows] = await Promise.all([
|
||||||
eventId: schema.scoringEvents.id,
|
db
|
||||||
scheduledAt: schema.playoffMatchGames.scheduledAt,
|
.select({
|
||||||
})
|
eventId: schema.scoringEvents.id,
|
||||||
.from(schema.scoringEvents)
|
scheduledAt: schema.playoffMatchGames.scheduledAt,
|
||||||
.innerJoin(
|
})
|
||||||
schema.playoffMatches,
|
.from(schema.scoringEvents)
|
||||||
eq(schema.playoffMatches.scoringEventId, schema.scoringEvents.id)
|
.innerJoin(
|
||||||
)
|
schema.playoffMatches,
|
||||||
.innerJoin(
|
eq(schema.playoffMatches.scoringEventId, schema.scoringEvents.id)
|
||||||
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)
|
|
||||||
)
|
)
|
||||||
);
|
.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>();
|
const earliestGameById = new Map<string, Date>();
|
||||||
for (const row of gameTimeRows) {
|
for (const row of [...gameTimeRows, ...groupStageTimeRows]) {
|
||||||
if (!row.scheduledAt) continue;
|
if (!row.scheduledAt) continue;
|
||||||
const prev = earliestGameById.get(row.eventId);
|
const prev = earliestGameById.get(row.eventId);
|
||||||
if (!prev || row.scheduledAt < prev) {
|
if (!prev || row.scheduledAt < prev) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue