diff options
author | mat <github@matdoes.dev> | 2022-03-31 21:50:39 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-03-31 21:50:39 -0500 |
commit | c3f939df6f95fa92862628102f6278f3de72e3ba (patch) | |
tree | cdba491b2ea6368b27b3488c5078aee5cd2ef429 /src | |
parent | 36134e0ee0f5097260306f48f548bcf5a5edae42 (diff) | |
download | skyblock-api-c3f939df6f95fa92862628102f6278f3de72e3ba.tar.gz skyblock-api-c3f939df6f95fa92862628102f6278f3de72e3ba.tar.bz2 skyblock-api-c3f939df6f95fa92862628102f6278f3de72e3ba.zip |
don't require server restart for updating removed profiles
Diffstat (limited to 'src')
-rw-r--r-- | src/database.ts | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/database.ts b/src/database.ts index 505efda..394b58b 100644 --- a/src/database.ts +++ b/src/database.ts @@ -34,14 +34,14 @@ const recentlyQueued = new NodeCache({ interface DatabaseMemberLeaderboardItem { uuid: string profile: string - stats: any + stats: Record<string, number> lastUpdated: Date } interface DatabaseProfileLeaderboardItem { uuid: string /** An array of uuids for each player in the profile */ players: string[] - stats: any + stats: Record<string, number> lastUpdated: Date } @@ -652,18 +652,22 @@ async function getApplicableProfileLeaderboardAttributes(profile: CleanFullProfi * deleted. This only makes one database call if there's no profiles to delete. */ export async function removeDeletedProfilesFromLeaderboards(memberUuid: string, profilesUuids: string[]) { - const profilesUuidsFromDatabase = (await (await memberLeaderboardsCollection.find({ + const leaderboardProfilesInDatabase = (await (await memberLeaderboardsCollection.find({ uuid: memberUuid, - })).toArray()).map(m => m.profile) + })).toArray()) - for (const profileUuid of profilesUuidsFromDatabase) { - if (!profilesUuids.includes(profileUuid)) { + for (const leaderboardProfile of leaderboardProfilesInDatabase) { + if (!profilesUuids.includes(leaderboardProfile.profile)) { await memberLeaderboardsCollection.deleteOne({ uuid: memberUuid, - profile: profileUuid + profile: leaderboardProfile.profile }) - if (debug) - console.log(`Profile ${profileUuid} (member ${memberUuid}) was deleted but was still in leaderboards database, removed.`) + if (debug) { + console.log(`Profile ${leaderboardProfile.profile} (member ${memberUuid}) was deleted but was still in leaderboards database, removed.`) + } + for (const leaderboardName in leaderboardProfile.stats) + // we want to refresh the leaderboard so we just remove the cache + cachedRawLeaderboards.delete(leaderboardName) } } } |