Fix team having many tournament level check-ins

Concrete bug it caused: wrong team count for tournament card on the front page
This commit is contained in:
Kalle 2026-04-27 18:05:49 +03:00
parent 1ef646a5c1
commit ec981d586e
14 changed files with 30 additions and 3 deletions

View File

@ -490,7 +490,9 @@ export function forShowcase() {
eb("CalendarEventDate.startTime", ">", databaseTimestampNow()),
]),
)
.select(({ fn }) => [fn.countAll<number>().as("teamsCount")])
.select(({ fn }) => [
fn.count<number>("TournamentTeam.id").distinct().as("teamsCount"),
])
.as("teamsCount"),
tournamentLogoWithDefault(eb).as("logoUrl"),
jsonObjectFrom(

View File

@ -423,11 +423,17 @@ export function checkIn(
return db.transaction().execute(async (trx) => {
let query = trx
.deleteFrom("TournamentTeamCheckIn")
.where("TournamentTeamCheckIn.tournamentTeamId", "=", tournamentTeamId)
.where("TournamentTeamCheckIn.isCheckOut", "=", 1);
.where("TournamentTeamCheckIn.tournamentTeamId", "=", tournamentTeamId);
if (typeof bracketIdx === "number") {
query = query.where("TournamentTeamCheckIn.bracketIdx", "=", bracketIdx);
} else {
query = query.where((eb) =>
eb.or([
eb("TournamentTeamCheckIn.isCheckOut", "=", 1),
eb("TournamentTeamCheckIn.bracketIdx", "is", null),
]),
);
}
await query.execute();

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,19 @@
export function up(db) {
db.transaction(() => {
db.prepare(
/* sql */ `
delete from "TournamentTeamCheckIn"
where "rowid" not in (
select max("rowid")
from "TournamentTeamCheckIn"
group by "tournamentTeamId", coalesce("bracketIdx", -1)
)`,
).run();
db.prepare(
/* sql */ `
create unique index "tournament_team_check_in_team_bracket_unique"
on "TournamentTeamCheckIn"("tournamentTeamId", coalesce("bracketIdx", -1))`,
).run();
})();
}