aboutsummaryrefslogtreecommitdiff
path: root/src/database.ts
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-06-01 17:17:12 -0500
committermat <github@matdoes.dev>2021-06-01 17:17:12 -0500
commit58cf3377dfcb47d58e2ef936dcbbfa99c37783c4 (patch)
treeb51bc425acbdf7e716ba351919bc2bfcb629075b /src/database.ts
parentaeb5f0d176d11a3b15d98e136ad9e420fd6cb416 (diff)
downloadskyblock-api-58cf3377dfcb47d58e2ef936dcbbfa99c37783c4.tar.gz
skyblock-api-58cf3377dfcb47d58e2ef936dcbbfa99c37783c4.tar.bz2
skyblock-api-58cf3377dfcb47d58e2ef936dcbbfa99c37783c4.zip
make new "cache" for recentlyqueued
Diffstat (limited to 'src/database.ts')
-rw-r--r--src/database.ts13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/database.ts b/src/database.ts
index 2c0a715..47cddbd 100644
--- a/src/database.ts
+++ b/src/database.ts
@@ -24,6 +24,13 @@ const recentlyUpdated = new NodeCache({
useClones: false,
})
+// don't add stuff to the queue within the same 5 minutes
+const recentlyQueued = new NodeCache({
+ stdTTL: 60 * 5,
+ checkperiod: 60,
+ useClones: false,
+})
+
interface DatabaseMemberLeaderboardItem {
uuid: string
profile: string
@@ -661,13 +668,15 @@ export const leaderboardUpdateProfileQueue = new Queue({
/** Queue an update for the member's leaderboard data on the server if applicable */
export function queueUpdateDatabaseMember(member: CleanMember, profile: CleanFullProfile): void {
- if (recentlyUpdated.get(profile.uuid + member.uuid)) return
+ if (recentlyQueued.get(profile.uuid + member.uuid)) return
+ else recentlyQueued.set(profile.uuid + member.uuid, true)
leaderboardUpdateMemberQueue.enqueue(async() => await updateDatabaseMember(member, profile))
}
/** Queue an update for the profile's leaderboard data on the server if applicable */
export function queueUpdateDatabaseProfile(profile: CleanFullProfile): void {
- if (recentlyUpdated.get(profile.uuid + 'profile')) return
+ if (recentlyQueued.get(profile.uuid + 'profile')) return
+ else recentlyQueued.set(profile.uuid + 'profile', true)
leaderboardUpdateProfileQueue.enqueue(async() => await updateDatabaseProfile(profile))
}