mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-27 05:54:13 -05:00
Deprecate tournament team page DB call in favor of derived data
This commit is contained in:
parent
1823c9881c
commit
8563a4956a
|
|
@ -5,7 +5,14 @@ import { sourceTypes } from "~/modules/tournament-map-list-generator/constants";
|
|||
import type { TournamentMaplistSource } from "~/modules/tournament-map-list-generator/types";
|
||||
import invariant from "~/utils/invariant";
|
||||
import { logger } from "~/utils/logger";
|
||||
import type { findRoundsByTournamentId } from "../queries/findRoundsByTournamentId.server";
|
||||
|
||||
export interface AllRoundsItem {
|
||||
stageId: number;
|
||||
stageName: string;
|
||||
stageType: Tables["TournamentStage"]["type"];
|
||||
roundNumber: number;
|
||||
groupNumber: number;
|
||||
}
|
||||
|
||||
export interface PlayedSet {
|
||||
tournamentMatchId: number;
|
||||
|
|
@ -79,7 +86,7 @@ export function tournamentTeamSets({
|
|||
allRounds,
|
||||
}: {
|
||||
sets: FindByTournamentTeamIdItem[];
|
||||
allRounds: ReturnType<typeof findRoundsByTournamentId>;
|
||||
allRounds: AllRoundsItem[];
|
||||
}): PlayedSet[] {
|
||||
return sets.map((set) => {
|
||||
const round =
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@ import type { LoaderFunctionArgs } from "react-router";
|
|||
import { tournamentDataCached } from "~/features/tournament-bracket/core/Tournament.server";
|
||||
import * as TournamentMatchRepository from "~/features/tournament-bracket/TournamentMatchRepository.server";
|
||||
import { tournamentTeamPageParamsSchema } from "~/features/tournament-bracket/tournament-bracket-schemas.server";
|
||||
import invariant from "~/utils/invariant";
|
||||
import { parseParams } from "~/utils/remix.server";
|
||||
import { tournamentTeamSets, winCounts } from "../core/sets.server";
|
||||
import { findRoundsByTournamentId } from "../queries/findRoundsByTournamentId.server";
|
||||
import {
|
||||
type AllRoundsItem,
|
||||
tournamentTeamSets,
|
||||
winCounts,
|
||||
} from "../core/sets.server";
|
||||
|
||||
export const loader = async ({ params }: LoaderFunctionArgs) => {
|
||||
const { id: tournamentId, tid: tournamentTeamId } = parseParams({
|
||||
|
|
@ -19,7 +23,19 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
|
|||
|
||||
const setHistory =
|
||||
await TournamentMatchRepository.findByTournamentTeamId(tournamentTeamId);
|
||||
const allRounds = findRoundsByTournamentId(tournamentId);
|
||||
const allRounds: AllRoundsItem[] = tournament.data.round.map((round) => {
|
||||
const stage = tournament.data.stage.find((s) => s.id === round.stage_id);
|
||||
const group = tournament.data.group.find((g) => g.id === round.group_id);
|
||||
invariant(stage && group, "Stage or group not found for round");
|
||||
|
||||
return {
|
||||
stageId: stage.id,
|
||||
stageName: stage.name,
|
||||
stageType: stage.type,
|
||||
roundNumber: round.number,
|
||||
groupNumber: group.number,
|
||||
};
|
||||
});
|
||||
|
||||
const sets = tournamentTeamSets({ sets: setHistory, allRounds });
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
import { sql } from "~/db/sql";
|
||||
import type { Tables } from "~/db/tables";
|
||||
|
||||
const stm = sql.prepare(/* sql */ `
|
||||
select
|
||||
"TournamentStage"."id" as "stageId",
|
||||
"TournamentStage"."name" as "stageName",
|
||||
"TournamentStage"."type" as "stageType",
|
||||
"TournamentRound"."number" as "roundNumber",
|
||||
"TournamentGroup"."number" as "groupNumber"
|
||||
from "TournamentStage"
|
||||
left join "TournamentGroup" on "TournamentGroup"."stageId" = "TournamentStage"."id"
|
||||
left join "TournamentRound" on "TournamentRound"."groupId" = "TournamentGroup"."id"
|
||||
where "TournamentStage"."tournamentId" = @tournamentId
|
||||
group by "TournamentStage"."id", "TournamentRound"."number", "TournamentGroup"."number"
|
||||
`);
|
||||
|
||||
export function findRoundsByTournamentId(tournamentId: number) {
|
||||
return stm.all({ tournamentId }) as Array<{
|
||||
stageId: number;
|
||||
stageName: string;
|
||||
stageType: Tables["TournamentStage"]["type"];
|
||||
roundNumber: number;
|
||||
groupNumber: number;
|
||||
}>;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user