mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-12 06:06:28 -05:00
Fix tournament data cache not getting cleared on IGN change
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user