Skip to content

Commit

Permalink
feat: ensure players only appear once (#110)
Browse files Browse the repository at this point in the history
* feat: ensure players only appear once

* feat: remove !!!
  • Loading branch information
HenrySpartGlobal authored Jul 28, 2024
1 parent a4eb824 commit 554c905
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/db/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export interface MmrRating {
sigma: string | null;
counter: number | null;
game: string | null;
queue_channel_id: number | null;
time: number | null;
}

export interface Points {
Expand All @@ -33,11 +35,19 @@ export interface Points {
wins: number | null;
losses: number | null;
game: string | null;
queue_channel_id: number | null;
}

export interface QueueChannels {
guild_id: number | null;
channel_id: number | null;
unique_leaderboard: boolean | null;
}

export interface DB {
games: Games;
igns: Igns;
mmr_rating: MmrRating;
points: Points;
queuechannels: QueueChannels;
}
8 changes: 7 additions & 1 deletion src/db/queries/leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ export async function fetchLeaderboardRaw(
let builder = db
.selectFrom("mmr_rating")
.where("mmr_rating.guild_id", "=", guildId)
// join with mmr_rating, same user_id and guild_id
.where("mmr_rating.time", "=",
(qb) => qb.selectFrom("mmr_rating as latest_mmr")
.select(sql<number>`MAX(${sql.ref('latest_mmr.time')})`.as("max_time"))
.whereRef("latest_mmr.user_id", "=", "mmr_rating.user_id")
.where("latest_mmr.guild_id", "=", guildId)
)
// join with points, same user_id and guild_id
.leftJoin("points", (eb) => eb.on(b => b.and([
b(b.ref("points.user_id"), "=", b.ref("mmr_rating.user_id")),
b(b.ref("points.guild_id"), "=", b.ref("mmr_rating.guild_id"))
Expand Down

0 comments on commit 554c905

Please sign in to comment.