claude/cool-lamport-etpwsi #96
1 changed files with 43 additions and 22 deletions
|
|
@ -310,10 +310,13 @@ 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
|
|
||||||
|
const [gameTimeRows, groupStageTimeRows] = await Promise.all([
|
||||||
|
db
|
||||||
.select({
|
.select({
|
||||||
eventId: schema.scoringEvents.id,
|
eventId: schema.scoringEvents.id,
|
||||||
scheduledAt: schema.playoffMatchGames.scheduledAt,
|
scheduledAt: schema.playoffMatchGames.scheduledAt,
|
||||||
|
|
@ -333,10 +336,28 @@ export async function getUpcomingScoringEvents(
|
||||||
isNotNull(schema.playoffMatchGames.scheduledAt),
|
isNotNull(schema.playoffMatchGames.scheduledAt),
|
||||||
gte(schema.playoffMatchGames.scheduledAt, now)
|
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