mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-20 01:55:26 -05:00
Refactor tournament data loading (#3298)
This commit is contained in:
@@ -34,6 +34,7 @@ import * as SavedCalendarEventRepository from "~/features/tournament/SavedCalend
|
||||
import * as TournamentAuditLogRepository from "~/features/tournament/TournamentAuditLogRepository.server";
|
||||
import * as TournamentRepository from "~/features/tournament/TournamentRepository.server";
|
||||
import * as TournamentTeamRepository from "~/features/tournament/TournamentTeamRepository.server";
|
||||
import * as BracketRepository from "~/features/tournament-bracket/BracketRepository.server";
|
||||
import * as TournamentMatchVodRepository from "~/features/tournament-bracket/TournamentMatchVodRepository.server";
|
||||
import * as TournamentLFGRepository from "~/features/tournament-lfg/TournamentLFGRepository.server";
|
||||
import * as TournamentMatchRepository from "~/features/tournament-match/TournamentMatchRepository.server";
|
||||
@@ -657,6 +658,13 @@ export function buildCases(fx: Fixtures): {
|
||||
XRankPlacementRepository.findPeaksByUserId(xrank.userId, "both"),
|
||||
);
|
||||
|
||||
// BracketRepository
|
||||
add(
|
||||
"BracketRepository.findByTournamentId",
|
||||
fx.heaviestBracketTournamentId,
|
||||
(tournamentId) => BracketRepository.findByTournamentId(tournamentId),
|
||||
);
|
||||
|
||||
// TournamentMatchVodRepository
|
||||
add(
|
||||
"TournamentMatchVodRepository.findVodsByTournamentId",
|
||||
@@ -876,6 +884,24 @@ export function buildCases(fx: Fixtures): {
|
||||
add("TournamentRepository.findById", fx.heavyTournamentId, (tournamentId) =>
|
||||
TournamentRepository.findById(tournamentId),
|
||||
);
|
||||
add(
|
||||
"TournamentRepository.findStreamsByTournamentId",
|
||||
fx.heavyTournamentId,
|
||||
(tournamentId) =>
|
||||
TournamentRepository.findStreamsByTournamentId(tournamentId),
|
||||
);
|
||||
add(
|
||||
"TournamentRepository.findTeamsFullByTournamentId",
|
||||
fx.heavyTournamentId,
|
||||
(tournamentId) =>
|
||||
TournamentRepository.findTeamsFullByTournamentId(tournamentId),
|
||||
);
|
||||
add(
|
||||
"TournamentRepository.findParticipatedUserIdsById",
|
||||
fx.heavyTournamentId,
|
||||
(tournamentId) =>
|
||||
TournamentRepository.findParticipatedUserIdsById(tournamentId),
|
||||
);
|
||||
add(
|
||||
"TournamentRepository.findRulesById",
|
||||
fx.heavyTournamentId,
|
||||
@@ -910,6 +936,12 @@ export function buildCases(fx: Fixtures): {
|
||||
(parentTournamentId) =>
|
||||
TournamentRepository.findChildTournamentsForDivCalc(parentTournamentId),
|
||||
);
|
||||
add(
|
||||
"TournamentRepository.findResultsByTournamentId",
|
||||
fx.heavyResultsTournamentId,
|
||||
(tournamentId) =>
|
||||
TournamentRepository.findResultsByTournamentId(tournamentId),
|
||||
);
|
||||
add(
|
||||
"TournamentRepository.findLeagueDivParticipantUserIds",
|
||||
fx.parentTournamentId,
|
||||
@@ -932,6 +964,12 @@ export function buildCases(fx: Fixtures): {
|
||||
(tournamentIds) =>
|
||||
TournamentRepository.findRelatedUsersByTournamentIds(tournamentIds),
|
||||
);
|
||||
add(
|
||||
"TournamentRepository.findParticipantTwitchAccounts",
|
||||
fx.recentTournamentIds,
|
||||
(tournamentIds) =>
|
||||
TournamentRepository.findParticipantTwitchAccounts(tournamentIds),
|
||||
);
|
||||
addStatic("TournamentRepository.findAllForShowcase", () =>
|
||||
TournamentRepository.findAllForShowcase(),
|
||||
);
|
||||
@@ -976,6 +1014,11 @@ export function buildCases(fx: Fixtures): {
|
||||
(teamIds) =>
|
||||
TournamentTeamRepository.findRecentlyPlayedMapsByIds({ teamIds }),
|
||||
);
|
||||
add(
|
||||
"TournamentTeamRepository.findMapPoolsByTeamIds",
|
||||
fx.tournamentTeamPair,
|
||||
(teamIds) => TournamentTeamRepository.findMapPoolsByTeamIds(teamIds),
|
||||
);
|
||||
|
||||
// TrophyRepository
|
||||
addStatic("TrophyRepository.all", () => TrophyRepository.all());
|
||||
@@ -1011,6 +1054,9 @@ export function buildCases(fx: Fixtures): {
|
||||
add("UserRepository.findCountriesByUserIds", fx.skillBatch, (skillBatch) =>
|
||||
UserRepository.findCountriesByUserIds(skillBatch.userIds),
|
||||
);
|
||||
add("UserRepository.findPlusTiersByUserIds", fx.skillBatch, (skillBatch) =>
|
||||
UserRepository.findPlusTiersByUserIds(skillBatch.userIds),
|
||||
);
|
||||
add("UserRepository.findBuildFieldsByIdentifier", fx.heavyUser, (user) =>
|
||||
UserRepository.findBuildFieldsByIdentifier(user.identifier),
|
||||
);
|
||||
|
||||
@@ -28,6 +28,10 @@ export interface Fixtures {
|
||||
heavyGroupIds: [number, number] | null;
|
||||
heavyStageModeCombo: { stageId: StageId; mode: ModeShort } | null;
|
||||
heavyTournamentId: number | null;
|
||||
/** Tournament with the most matches. Unlike `heavyTournamentId` (most teams) this one is guaranteed to have brackets. */
|
||||
heaviestBracketTournamentId: number | null;
|
||||
/** Finalized tournament with the most persisted results. */
|
||||
heavyResultsTournamentId: number | null;
|
||||
heavyTournamentMatchId: number | null;
|
||||
tournamentMatchGameResultId: number | null;
|
||||
heavyTournamentTeamId: number | null;
|
||||
@@ -121,6 +125,8 @@ export async function resolveFixtures(): Promise<Fixtures> {
|
||||
heavyGroupIds: await resolveHeavyGroupIds(heavyGroupMatchId),
|
||||
heavyStageModeCombo: await resolveHeavyStageModeCombo(),
|
||||
heavyTournamentId,
|
||||
heaviestBracketTournamentId: await resolveHeaviestBracketTournamentId(),
|
||||
heavyResultsTournamentId: await resolveHeavyResultsTournamentId(),
|
||||
heavyTournamentMatchId: await resolveHeavyTournamentMatchId(),
|
||||
tournamentMatchGameResultId: await resolveTournamentMatchGameResultId(),
|
||||
heavyTournamentTeamId:
|
||||
@@ -389,6 +395,38 @@ async function resolveHeavyTournamentId() {
|
||||
return row?.tournamentId ?? null;
|
||||
}
|
||||
|
||||
async function resolveHeaviestBracketTournamentId() {
|
||||
const row = await db
|
||||
.selectFrom("TournamentMatch")
|
||||
.innerJoin(
|
||||
"TournamentStage",
|
||||
"TournamentStage.id",
|
||||
"TournamentMatch.stageId",
|
||||
)
|
||||
.select(({ fn }) => [
|
||||
"TournamentStage.tournamentId",
|
||||
fn.countAll<number>().as("count"),
|
||||
])
|
||||
.groupBy("TournamentStage.tournamentId")
|
||||
.orderBy("count", "desc")
|
||||
.limit(1)
|
||||
.executeTakeFirst();
|
||||
|
||||
return row?.tournamentId ?? null;
|
||||
}
|
||||
|
||||
async function resolveHeavyResultsTournamentId() {
|
||||
const row = await db
|
||||
.selectFrom("TournamentResult")
|
||||
.select(({ fn }) => ["tournamentId", fn.countAll<number>().as("count")])
|
||||
.groupBy("tournamentId")
|
||||
.orderBy("count", "desc")
|
||||
.limit(1)
|
||||
.executeTakeFirst();
|
||||
|
||||
return row?.tournamentId ?? null;
|
||||
}
|
||||
|
||||
async function resolveHeavyTournamentMatchId() {
|
||||
const row = await db
|
||||
.selectFrom("TournamentMatchGameResult")
|
||||
|
||||
Reference in New Issue
Block a user