mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-05 20:56:13 -05:00
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:
parent
1ef646a5c1
commit
ec981d586e
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
BIN
db-test.sqlite3
BIN
db-test.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19
migrations/135-tournament-team-check-in-unique.js
Normal file
19
migrations/135-tournament-team-check-in-unique.js
Normal 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();
|
||||
})();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user