aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/database.js30
-rw-r--r--src/database.ts35
2 files changed, 53 insertions, 12 deletions
diff --git a/build/database.js b/build/database.js
index 7e7331c..e08d4ec 100644
--- a/build/database.js
+++ b/build/database.js
@@ -212,11 +212,16 @@ async function fetchMemberLeaderboardRaw(name) {
const sortQuery = {};
sortQuery[`stats.${name}`] = isLeaderboardReversed(name) ? 1 : -1;
fetchingRawLeaderboardNames.add(name);
- const leaderboardRaw = await memberLeaderboardsCollection
+ const leaderboardRaw = (await memberLeaderboardsCollection
.find(query)
.sort(sortQuery)
.limit(leaderboardMax)
- .toArray();
+ .toArray())
+ .map((i) => {
+ const stats = {};
+ stats[name] = i.stats[name];
+ return { ...i, stats };
+ });
fetchingRawLeaderboardNames.delete(name);
exports.cachedRawLeaderboards.set(name, leaderboardRaw);
return leaderboardRaw;
@@ -238,11 +243,16 @@ async function fetchProfileLeaderboardRaw(name) {
const sortQuery = {};
sortQuery[`stats.${name}`] = isLeaderboardReversed(name) ? 1 : -1;
fetchingRawLeaderboardNames.add(name);
- const leaderboardRaw = await profileLeaderboardsCollection
+ const leaderboardRaw = (await profileLeaderboardsCollection
.find(query)
.sort(sortQuery)
.limit(leaderboardMax)
- .toArray();
+ .toArray())
+ .map((i) => {
+ const stats = {};
+ stats[name] = i.stats[name];
+ return { ...i, stats };
+ });
fetchingRawLeaderboardNames.delete(name);
exports.cachedRawLeaderboards.set(name, leaderboardRaw);
return leaderboardRaw;
@@ -416,12 +426,14 @@ async function updateDatabaseMember(member, profile) {
for (const [attributeName, attributeValue] of Object.entries(leaderboardAttributes)) {
const existingRawLeaderboard = await fetchMemberLeaderboardRaw(attributeName);
const leaderboardReverse = isLeaderboardReversed(attributeName);
+ const thisLeaderboardAttributes = {};
+ thisLeaderboardAttributes[attributeName] = attributeValue;
const newRawLeaderboard = existingRawLeaderboard
// remove the player from the leaderboard, if they're there
.filter(value => value.uuid !== member.uuid || value.profile !== profile.uuid)
.concat([{
last_updated: new Date(),
- stats: leaderboardAttributes,
+ stats: thisLeaderboardAttributes,
uuid: member.uuid,
profile: profile.uuid
}])
@@ -465,12 +477,14 @@ async function updateDatabaseProfile(profile) {
for (const [attributeName, attributeValue] of Object.entries(leaderboardAttributes)) {
const existingRawLeaderboard = await fetchProfileLeaderboardRaw(attributeName);
const leaderboardReverse = isLeaderboardReversed(attributeName);
+ const thisLeaderboardAttributes = {};
+ thisLeaderboardAttributes[attributeName] = attributeValue;
const newRawLeaderboard = existingRawLeaderboard
// remove the player from the leaderboard, if they're there
.filter(value => value.uuid !== profile.uuid)
.concat([{
last_updated: new Date(),
- stats: leaderboardAttributes,
+ stats: thisLeaderboardAttributes,
uuid: profile.uuid,
players: profile.members.map(p => p.uuid)
}])
@@ -592,3 +606,7 @@ if (!globalThis.isTest) {
setInterval(fetchAllLeaderboards, 4 * 60 * 60 * 1000);
});
}
+setInterval(() => {
+ console.log(exports.cachedRawLeaderboards.size);
+ console.log(Array.from(exports.cachedRawLeaderboards.values())[exports.cachedRawLeaderboards.size - 1]);
+}, 5000);
diff --git a/src/database.ts b/src/database.ts
index 2acfee5..0939e79 100644
--- a/src/database.ts
+++ b/src/database.ts
@@ -280,11 +280,16 @@ async function fetchMemberLeaderboardRaw(name: string): Promise<DatabaseMemberLe
sortQuery[`stats.${name}`] = isLeaderboardReversed(name) ? 1 : -1
fetchingRawLeaderboardNames.add(name)
- const leaderboardRaw: DatabaseMemberLeaderboardItem[] = await memberLeaderboardsCollection
+ const leaderboardRaw: DatabaseMemberLeaderboardItem[] = (await memberLeaderboardsCollection
.find(query)
.sort(sortQuery)
.limit(leaderboardMax)
- .toArray()
+ .toArray())
+ .map((i: DatabaseMemberLeaderboardItem): DatabaseMemberLeaderboardItem => {
+ const stats = {}
+ stats[name] = i.stats[name]
+ return { ...i, stats }
+ })
fetchingRawLeaderboardNames.delete(name)
cachedRawLeaderboards.set(name, leaderboardRaw)
return leaderboardRaw
@@ -311,11 +316,16 @@ async function fetchProfileLeaderboardRaw(name: string): Promise<DatabaseProfile
sortQuery[`stats.${name}`] = isLeaderboardReversed(name) ? 1 : -1
fetchingRawLeaderboardNames.add(name)
- const leaderboardRaw: DatabaseProfileLeaderboardItem[] = await profileLeaderboardsCollection
+ const leaderboardRaw: DatabaseProfileLeaderboardItem[] = (await profileLeaderboardsCollection
.find(query)
.sort(sortQuery)
.limit(leaderboardMax)
- .toArray()
+ .toArray())
+ .map((i: DatabaseProfileLeaderboardItem): DatabaseProfileLeaderboardItem => {
+ const stats = {}
+ stats[name] = i.stats[name]
+ return { ...i, stats }
+ })
fetchingRawLeaderboardNames.delete(name)
cachedRawLeaderboards.set(name, leaderboardRaw)
@@ -537,12 +547,16 @@ export async function updateDatabaseMember(member: CleanMember, profile: CleanFu
for (const [ attributeName, attributeValue ] of Object.entries(leaderboardAttributes)) {
const existingRawLeaderboard = await fetchMemberLeaderboardRaw(attributeName)
const leaderboardReverse = isLeaderboardReversed(attributeName)
+
+ const thisLeaderboardAttributes = {}
+ thisLeaderboardAttributes[attributeName] = attributeValue
+
const newRawLeaderboard = existingRawLeaderboard
// remove the player from the leaderboard, if they're there
.filter(value => value.uuid !== member.uuid || value.profile !== profile.uuid)
.concat([{
last_updated: new Date(),
- stats: leaderboardAttributes,
+ stats: thisLeaderboardAttributes,
uuid: member.uuid,
profile: profile.uuid
}])
@@ -592,12 +606,16 @@ export async function updateDatabaseProfile(profile: CleanFullProfile): Promise<
for (const [ attributeName, attributeValue ] of Object.entries(leaderboardAttributes)) {
const existingRawLeaderboard = await fetchProfileLeaderboardRaw(attributeName)
const leaderboardReverse = isLeaderboardReversed(attributeName)
+
+ const thisLeaderboardAttributes = {}
+ thisLeaderboardAttributes[attributeName] = attributeValue
+
const newRawLeaderboard = existingRawLeaderboard
// remove the player from the leaderboard, if they're there
.filter(value => value.uuid !== profile.uuid)
.concat([{
last_updated: new Date(),
- stats: leaderboardAttributes,
+ stats: thisLeaderboardAttributes,
uuid: profile.uuid,
players: profile.members.map(p => p.uuid)
}])
@@ -730,3 +748,8 @@ if (!globalThis.isTest) {
setInterval(fetchAllLeaderboards, 4 * 60 * 60 * 1000)
})
}
+
+setInterval(() => {
+ console.log(cachedRawLeaderboards.size)
+ console.log(Array.from(cachedRawLeaderboards.values())[cachedRawLeaderboards.size - 1])
+}, 5000) \ No newline at end of file