From 05005eba5b3f5d3bd68b19edd542e39ac3ea80d0 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Fri, 24 May 2024 21:41:37 +0300 Subject: [PATCH] Stop showing unfinalized tournaments on the front page after some time --- .../tournament/TournamentRepository.server.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/features/tournament/TournamentRepository.server.ts b/app/features/tournament/TournamentRepository.server.ts index a8a4273be..457448adf 100644 --- a/app/features/tournament/TournamentRepository.server.ts +++ b/app/features/tournament/TournamentRepository.server.ts @@ -1,3 +1,4 @@ +import { add } from "date-fns"; import type { Insertable, NotNull, Transaction } from "kysely"; import { jsonArrayFrom, jsonObjectFrom } from "kysely/helpers/sqlite"; import { nanoid } from "nanoid"; @@ -5,7 +6,10 @@ import { db } from "~/db/sql"; import type { CastedMatchesInfo, DB, Tables } from "~/db/tables"; import { Status } from "~/modules/brackets-model"; import { modesShort } from "~/modules/in-game-lists"; -import { dateToDatabaseTimestamp } from "~/utils/dates"; +import { + databaseTimestampToDate, + dateToDatabaseTimestamp, +} from "~/utils/dates"; import { COMMON_USER_FIELDS, userChatNameColor } from "~/utils/kysely.server"; export async function findById(id: number) { @@ -250,6 +254,13 @@ export async function forShowcase() { for (const row of rows) { if (row.id === latestWinners?.id) break; + + // if they did not finalize the tournament for whatever reason, lets just stop showing it after 6 hours + if ( + new Date() > add(databaseTimestampToDate(row.startTime), { hours: 6 }) + ) { + continue; + } next.unshift(row); if (next.length > nextTournamentsCount) next.pop();