aboutsummaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authormat-1 <github@matdoes.dev>2021-02-28 22:20:01 +0000
committermat-1 <github@matdoes.dev>2021-02-28 22:20:01 +0000
commit4bd57f0451f3b136dc0dcb8a5964aacf4610b40c (patch)
tree812d0fb2e19d820873e7dc8a75720e00a2b3f3d7 /build
parent37b8857107e529344b2077409aaeff5efe9a2432 (diff)
downloadskyblock-api-4bd57f0451f3b136dc0dcb8a5964aacf4610b40c.tar.gz
skyblock-api-4bd57f0451f3b136dc0dcb8a5964aacf4610b40c.tar.bz2
skyblock-api-4bd57f0451f3b136dc0dcb8a5964aacf4610b40c.zip
Compiled TS into JS
Diffstat (limited to 'build')
-rw-r--r--build/database.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/build/database.js b/build/database.js
index a813a78..d400677 100644
--- a/build/database.js
+++ b/build/database.js
@@ -41,6 +41,9 @@ const recentlyUpdated = new node_cache_1.default({
const cachedRawLeaderboards = new Map();
const cachedLeaderboards = new Map();
const leaderboardMax = 100;
+const reversedStats = [
+ 'first_join'
+];
let client;
let database;
let memberLeaderboardsCollection;
@@ -102,14 +105,17 @@ async function fetchAllMemberLeaderboardAttributes() {
];
}
exports.fetchAllMemberLeaderboardAttributes = fetchAllMemberLeaderboardAttributes;
+function isLeaderboardReversed(name) {
+ return reversedStats.includes(name);
+}
async function fetchMemberLeaderboardRaw(name) {
if (cachedRawLeaderboards.has(name))
return cachedRawLeaderboards.get(name);
// typescript forces us to make a new variable and set it this way because it gives an error otherwise
const query = {};
- query[`stats.${name}`] = { '$exists': true };
+ query[`stats.${name}`] = { '$exists': true, '$ne': NaN };
const sortQuery = {};
- sortQuery[`stats.${name}`] = -1;
+ sortQuery[`stats.${name}`] = isLeaderboardReversed(name) ? 1 : -1;
const leaderboardRaw = await memberLeaderboardsCollection.find(query).sort(sortQuery).limit(leaderboardMax).toArray();
cachedRawLeaderboards.set(name, leaderboardRaw);
return leaderboardRaw;
@@ -173,6 +179,7 @@ async function updateDatabaseMember(member, profile) {
for (const [attributeName, attributeValue] of Object.entries(leaderboardAttributes)) {
const existingLeaderboard = await fetchMemberLeaderboard(attributeName);
const existingRawLeaderboard = await fetchMemberLeaderboardRaw(attributeName);
+ const leaderboardReverse = isLeaderboardReversed(attributeName);
const newLeaderboard = existingLeaderboard
// remove the player from the leaderboard, if they're there
.filter(value => value.player.uuid !== member.uuid)
@@ -180,7 +187,7 @@ async function updateDatabaseMember(member, profile) {
player: await cached.fetchPlayer(member.uuid),
value: attributeValue
}])
- .sort((a, b) => b.value - a.value)
+ .sort((a, b) => leaderboardReverse ? a.value - b.value : b.value - a.value)
.slice(0, 100);
const newRawLeaderboard = existingRawLeaderboard
// remove the player from the leaderboard, if they're there
@@ -190,7 +197,7 @@ async function updateDatabaseMember(member, profile) {
stats: leaderboardAttributes,
uuid: member.uuid
}])
- .sort((a, b) => b.stats[attributeName] - a.stats[attributeName])
+ .sort((a, b) => leaderboardReverse ? a.stats[attributeName] - b.stats[attributeName] : b.stats[attributeName] - a.stats[attributeName])
.slice(0, 100);
cachedLeaderboards.set(attributeName, newLeaderboard);
cachedRawLeaderboards.set(attributeName, newRawLeaderboard);