Fix tournament data cache not getting cleared on IGN change
Some checks are pending
Tests and checks on push / run-checks-and-tests (push) Waiting to run
Updates translation progress / update-translation-progress-issue (push) Waiting to run

This commit is contained in:
Kalle
2025-02-16 21:57:28 +02:00
parent 6a027d5481
commit f0d9024731
2 changed files with 40 additions and 22 deletions

View File

@@ -23,7 +23,7 @@ export function setActiveRoster({
.execute();
}
const regOpenTournamentTeamIdsByJoinedUserId = (userId: number) =>
const regOpenTournamentTeamsByJoinedUserId = (userId: number) =>
db
.selectFrom("TournamentTeamMember")
.innerJoin(
@@ -38,7 +38,10 @@ const regOpenTournamentTeamIdsByJoinedUserId = (userId: number) =>
"CalendarEventDate.eventId",
"CalendarEvent.id",
)
.select("TournamentTeamMember.tournamentTeamId")
.select([
"TournamentTeam.tournamentId",
"TournamentTeamMember.tournamentTeamId",
])
.where("TournamentTeamMember.userId", "=", userId)
.where(
sql`coalesce(
@@ -48,8 +51,7 @@ const regOpenTournamentTeamIdsByJoinedUserId = (userId: number) =>
">",
databaseTimestampNow(),
)
.execute()
.then((rows) => rows.map((row) => row.tournamentTeamId));
.execute();
export async function updateMemberInGameName({
userId,
@@ -68,27 +70,37 @@ export async function updateMemberInGameName({
.execute();
}
/**
* Updates the in-game name of a tournament team member for tournaments that have not started yet.
*
* @returns A promise that resolves to an array of tournament IDs where the user's in-game name was updated.
*/
export async function updateMemberInGameNameForNonStarted({
userId,
inGameName,
}: {
/** The ID of the user whose in-game name is to be updated. */
userId: number;
/** The new in-game name to be set for the user. */
inGameName: string;
}) {
const tournamentTeamIds =
await regOpenTournamentTeamIdsByJoinedUserId(userId);
}): Promise<number[]> {
const tournamentTeams = await regOpenTournamentTeamsByJoinedUserId(userId);
return (
db
.updateTable("TournamentTeamMember")
.set({ inGameName })
.where("TournamentTeamMember.userId", "=", userId)
// after they have checked in no longer can update their IGN from here
.where("TournamentTeamMember.tournamentTeamId", "in", tournamentTeamIds)
// if the tournament doesn't have the setting to require IGN, ignore
.where("TournamentTeamMember.inGameName", "is not", null)
.execute()
);
await db
.updateTable("TournamentTeamMember")
.set({ inGameName })
.where("TournamentTeamMember.userId", "=", userId)
// after they have checked in no longer can update their IGN from here
.where(
"TournamentTeamMember.tournamentTeamId",
"in",
tournamentTeams.map((t) => t.tournamentTeamId),
)
// if the tournament doesn't have the setting to require IGN, ignore
.where("TournamentTeamMember.inGameName", "is not", null)
.execute();
return tournamentTeams.map((t) => t.tournamentId);
}
export function create({

View File

@@ -55,6 +55,7 @@ import { userParamsSchema } from "../user-page-schemas.server";
import type { UserPageLoaderData } from "./u.$identifier";
import "~/styles/u-edit.css";
import { SendouSwitch } from "~/components/elements/Switch";
import { clearTournamentDataCache } from "~/features/tournament-bracket/core/Tournament.server";
export const userEditActionSchema = z
.object({
@@ -192,10 +193,15 @@ export const action: ActionFunction = async ({ request }) => {
// TODO: to transaction
if (inGameName) {
await TournamentTeamRepository.updateMemberInGameNameForNonStarted({
inGameName,
userId: user.id,
});
const tournamentIdsAffected =
await TournamentTeamRepository.updateMemberInGameNameForNonStarted({
inGameName,
userId: user.id,
});
for (const tournamentId of tournamentIdsAffected) {
clearTournamentDataCache(tournamentId);
}
}
throw redirect(userPage(editedUser));