diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-28 02:32:33 -0600 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-28 02:32:33 -0600 |
commit | a899de303a30198d091974beb2eaab7b1d38bf34 (patch) | |
tree | ff3812fdc175f8de1e41611dea5a373fdd165835 | |
parent | 6145137197023d5be0556416f279c1e29cae3261 (diff) | |
download | skyblock-api-a899de303a30198d091974beb2eaab7b1d38bf34.tar.gz skyblock-api-a899de303a30198d091974beb2eaab7b1d38bf34.tar.bz2 skyblock-api-a899de303a30198d091974beb2eaab7b1d38bf34.zip |
make the max items in leaderboard easily changeable
-rw-r--r-- | src/database.ts | 8 |
1 files 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<string, any> = 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<LeaderboardItem> => { return { player: await cached.fetchPlayer(item.uuid), @@ -117,8 +119,8 @@ export async function fetchMemberLeaderboard(name: string) { async function getMemberLeaderboardRequirement(name: string): Promise<number> { 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 } |