From c3f939df6f95fa92862628102f6278f3de72e3ba Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 31 Mar 2022 21:50:39 -0500 Subject: don't require server restart for updating removed profiles --- src/database.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src') 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 lastUpdated: Date } interface DatabaseProfileLeaderboardItem { uuid: string /** An array of uuids for each player in the profile */ players: string[] - stats: any + stats: Record 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) } } } -- cgit