From b126dc753a6f682d39e6ca0b4f23e4d9f384ac1e Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Tue, 24 Feb 2026 20:49:30 +0200 Subject: [PATCH] Persist prepared maps for sibling bracket reuse --- .../actions/to.$id.brackets.server.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/features/tournament-bracket/actions/to.$id.brackets.server.ts b/app/features/tournament-bracket/actions/to.$id.brackets.server.ts index 05fcb4113..bc7c58f03 100644 --- a/app/features/tournament-bracket/actions/to.$id.brackets.server.ts +++ b/app/features/tournament-bracket/actions/to.$id.brackets.server.ts @@ -24,6 +24,7 @@ import { idObject } from "~/utils/zod"; import type { PreparedMaps } from "../../../db/tables"; import { getServerTournamentManager } from "../core/brackets-manager/manager.server"; import { roundMapsFromInput } from "../core/mapList.server"; +import * as PreparedMapsUtils from "../core/PreparedMaps"; import * as Swiss from "../core/Swiss"; import type { Tournament } from "../core/Tournament"; import { @@ -122,6 +123,27 @@ export const action: ActionFunction = async ({ params, request }) => { ); })(); + // persist maps as prepared even if they weren't initially so sibling brackets can reuse them + const existingPreparedMaps = + await TournamentRepository.findPreparedMapsById(tournamentId); + if (!existingPreparedMaps?.[data.bracketIdx]) { + await TournamentRepository.upsertPreparedMaps({ + bracketIdx: data.bracketIdx, + tournamentId, + maps: { + maps, + authorId: user.id, + eliminationTeamCount: + bracket.type === "single_elimination" || + bracket.type === "double_elimination" + ? PreparedMapsUtils.eliminationTeamCountOptions( + seeding.length, + )[0].max + : undefined, + }, + }); + } + // ensures autoseeding is disabled const isAllSeedsPersisted = tournament.ctx.teams.every( (team) => typeof team.seed === "number",