From 3b69df999f91a34580b4a75b1e95211e225c9fbb Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 30 May 2021 21:43:25 -0500 Subject: i think i found out why it's using so much memory. --- src/database.ts | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'src/database.ts') 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 { + 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 { + 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 -- cgit