From 1fc9c5936797facb4f6fd9eb194c94381b5aaba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Tue, 16 Jun 2026 01:44:38 +0200 Subject: [PATCH] fix: sort recentMatches by UTC kickoff time, not ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ID order doesn't reflect actual match time — a later kickoff in a different timezone can have a lower ID. Use the same UTC normalisation expression as upcomingMatches so the latest finished match always appears first. Co-Authored-By: Claude Sonnet 4.6 --- lib/graphql/resolvers/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/graphql/resolvers/index.ts b/lib/graphql/resolvers/index.ts index 0dc5d0f..71d4533 100644 --- a/lib/graphql/resolvers/index.ts +++ b/lib/graphql/resolvers/index.ts @@ -120,7 +120,17 @@ export const resolvers = { isNotNull(matches.scoreFtHome), eq(matches.isQualiPlayoff, false), )) - .orderBy(desc(matches.date), desc(matches.id)) + .orderBy( + sql`CASE + WHEN ${matches.timeLocal} LIKE '% UTC%' + THEN ${matches.date}::date + + SPLIT_PART(${matches.timeLocal}, ' ', 1)::time + - (REPLACE(SPLIT_PART(${matches.timeLocal}, ' ', 2), 'UTC', '') || ' hours')::interval + ELSE ${matches.date}::date + + COALESCE(NULLIF(SPLIT_PART(${matches.timeLocal}, ' ', 1), '')::time, '00:00'::time) + END DESC NULLS LAST`, + desc(matches.id), + ) .limit(limit * 2) const hydrated = await Promise.all(rows.map(hydrateMatch)) return hydrated.filter(m => !m.isLive).slice(0, limit)