diff options
author | mat <github@matdoes.dev> | 2022-03-31 21:44:29 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-03-31 21:44:29 -0500 |
commit | 36134e0ee0f5097260306f48f548bcf5a5edae42 (patch) | |
tree | 5e920b1ea6bf6eb8e14af6ec0a7e1c32b010c6ee /src/database.ts | |
parent | e92723ae05efcf41d6ced326c06fe53d9bcb4c1f (diff) | |
download | skyblock-api-36134e0ee0f5097260306f48f548bcf5a5edae42.tar.gz skyblock-api-36134e0ee0f5097260306f48f548bcf5a5edae42.tar.bz2 skyblock-api-36134e0ee0f5097260306f48f548bcf5a5edae42.zip |
remove deleted profiles from leaderboard
Diffstat (limited to 'src/database.ts')
-rw-r--r-- | src/database.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/database.ts b/src/database.ts index 8214208..505efda 100644 --- a/src/database.ts +++ b/src/database.ts @@ -647,6 +647,27 @@ async function getApplicableProfileLeaderboardAttributes(profile: CleanFullProfi return applicableAttributes } +/** + * Make sure there's no lingering profiles from when a player's profile was + * 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({ + uuid: memberUuid, + })).toArray()).map(m => m.profile) + + for (const profileUuid of profilesUuidsFromDatabase) { + if (!profilesUuids.includes(profileUuid)) { + await memberLeaderboardsCollection.deleteOne({ + uuid: memberUuid, + profile: profileUuid + }) + if (debug) + console.log(`Profile ${profileUuid} (member ${memberUuid}) was deleted but was still in leaderboards database, removed.`) + } + } +} + /** Update the member's leaderboard data on the server if applicable */ export async function updateDatabaseMember(member: CleanMember, profile: CleanFullProfile): Promise<void> { if (!client) return // the db client hasn't been initialized |