Persist prepared maps for sibling bracket reuse

This commit is contained in:
Kalle
2026-02-24 20:49:30 +02:00
parent 95a8fa3b8c
commit b126dc753a

View File

@@ -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",