From a899de303a30198d091974beb2eaab7b1d38bf34 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sun, 28 Feb 2021 02:32:33 -0600 Subject: make the max items in leaderboard easily changeable --- src/database.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/database.ts b/src/database.ts index 561fdb0..ac0265d 100644 --- a/src/database.ts +++ b/src/database.ts @@ -30,6 +30,8 @@ interface LeaderboardItem { const cachedLeaderboards: Map = new Map() +const leaderboardMax = 100 + let client: MongoClient let database: Db @@ -98,7 +100,7 @@ export async function fetchMemberLeaderboard(name: string) { sortQuery[`stats.${name}`] = -1 - const leaderboardRaw = await memberLeaderboardsCollection.find(query).sort(sortQuery).limit(100).toArray() + const leaderboardRaw = await memberLeaderboardsCollection.find(query).sort(sortQuery).limit(leaderboardMax).toArray() const fetchLeaderboardPlayer = async(item: DatabaseLeaderboardItem): Promise => { return { player: await cached.fetchPlayer(item.uuid), @@ -117,8 +119,8 @@ export async function fetchMemberLeaderboard(name: string) { async function getMemberLeaderboardRequirement(name: string): Promise { const leaderboard = await fetchMemberLeaderboard(name) // if there's more than 100 items, return the 100th. if there's less, return null - if (leaderboard.length >= 100) - return leaderboard[99].value + if (leaderboard.length >= leaderboardMax) + return leaderboard[leaderboardMax - 1].value else return null } -- cgit