mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-27 21:55:15 -05:00
Persist prepared maps for sibling bracket reuse
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user