From 54ef0305a3e20fdb2996d8ee8356e4bd9a8f9ae9 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Mon, 13 Oct 2025 18:46:56 +0300 Subject: [PATCH] Fix match page slowness (#2573) --- .../api-public/routes/tournament-match.$id.ts | 14 ++++++++------ .../actions/to.$id.matches.$mid.server.ts | 14 ++++++++------ .../tournament-bracket/core/mapList.server.ts | 2 +- .../loaders/to.$id.matches.$mid.server.ts | 14 ++++++++------ .../098-tournament-match-game-result-indexes.js | 7 +++++++ 5 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 migrations/098-tournament-match-game-result-indexes.js diff --git a/app/features/api-public/routes/tournament-match.$id.ts b/app/features/api-public/routes/tournament-match.$id.ts index b39e3bdb1..d3b5ffabd 100644 --- a/app/features/api-public/routes/tournament-match.$id.ts +++ b/app/features/api-public/routes/tournament-match.$id.ts @@ -130,12 +130,14 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => { maps: match.maps, pickBanEvents, recentlyPlayedMaps: - await TournamentTeamRepository.findRecentlyPlayedMapsByIds({ - teamIds: [match.opponentOne.id, match.opponentTwo.id], - }).catch((error) => { - logger.error("Failed to fetch recently played maps", error); - return []; - }), + match.mapPickingStyle !== "TO" + ? await TournamentTeamRepository.findRecentlyPlayedMapsByIds({ + teamIds: [match.opponentOne.id, match.opponentTwo.id], + }).catch((error) => { + logger.error("Failed to fetch recently played maps", error); + return []; + }) + : undefined, }).map((mapListMap) => { return { map: { diff --git a/app/features/tournament-bracket/actions/to.$id.matches.$mid.server.ts b/app/features/tournament-bracket/actions/to.$id.matches.$mid.server.ts index 2a175cf6e..5bbfdc671 100644 --- a/app/features/tournament-bracket/actions/to.$id.matches.$mid.server.ts +++ b/app/features/tournament-bracket/actions/to.$id.matches.$mid.server.ts @@ -95,12 +95,14 @@ export const action: ActionFunction = async ({ params, request }) => { maps: match.roundMaps, pickBanEvents, recentlyPlayedMaps: - await TournamentTeamRepository.findRecentlyPlayedMapsByIds({ - teamIds: [match.opponentOne.id, match.opponentTwo.id], - }).catch((error) => { - logger.error("Failed to fetch recently played maps", error); - return []; - }), + match.mapPickingStyle !== "TO" + ? await TournamentTeamRepository.findRecentlyPlayedMapsByIds({ + teamIds: [match.opponentOne.id, match.opponentTwo.id], + }).catch((error) => { + logger.error("Failed to fetch recently played maps", error); + return []; + }) + : undefined, }) : null; diff --git a/app/features/tournament-bracket/core/mapList.server.ts b/app/features/tournament-bracket/core/mapList.server.ts index 016d3399b..09d8b703d 100644 --- a/app/features/tournament-bracket/core/mapList.server.ts +++ b/app/features/tournament-bracket/core/mapList.server.ts @@ -30,7 +30,7 @@ interface ResolveCurrentMapListArgs { type: Tables["TournamentMatchPickBanEvent"]["type"]; }>; /** Maps that both teams (interleaved) have recently played in the tournament with the most recent being first. */ - recentlyPlayedMaps: Array<{ mode: ModeShort; stageId: StageId }>; + recentlyPlayedMaps?: Array<{ mode: ModeShort; stageId: StageId }>; } export function resolveMapList( diff --git a/app/features/tournament-bracket/loaders/to.$id.matches.$mid.server.ts b/app/features/tournament-bracket/loaders/to.$id.matches.$mid.server.ts index 01ed4d510..3cfde459e 100644 --- a/app/features/tournament-bracket/loaders/to.$id.matches.$mid.server.ts +++ b/app/features/tournament-bracket/loaders/to.$id.matches.$mid.server.ts @@ -37,12 +37,14 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { maps: match.roundMaps, pickBanEvents, recentlyPlayedMaps: - await TournamentTeamRepository.findRecentlyPlayedMapsByIds({ - teamIds: [match.opponentOne.id, match.opponentTwo.id], - }).catch((error) => { - logger.error("Failed to fetch recently played maps", error); - return []; - }), + match.mapPickingStyle !== "TO" + ? await TournamentTeamRepository.findRecentlyPlayedMapsByIds({ + teamIds: [match.opponentOne.id, match.opponentTwo.id], + }).catch((error) => { + logger.error("Failed to fetch recently played maps", error); + return []; + }) + : undefined, }) : null; diff --git a/migrations/098-tournament-match-game-result-indexes.js b/migrations/098-tournament-match-game-result-indexes.js new file mode 100644 index 000000000..919e7fe56 --- /dev/null +++ b/migrations/098-tournament-match-game-result-indexes.js @@ -0,0 +1,7 @@ +export function up(db) { + db.transaction(() => { + db.prepare( + /* sql */ `create index idx_tmgrp_tournament_team_id on "TournamentMatchGameResultParticipant"("tournamentTeamId")`, + ).run(); + })(); +}