aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-02-16 18:40:36 -0600
committermat <27899617+mat-1@users.noreply.github.com>2021-02-16 18:40:36 -0600
commit74c078392c46405a8432309c8672dc09642956d6 (patch)
treed94ffc3d6b448de1b670fd5cf8250730b89f24fc /src
parentb453d4835ef60624aba508e9aafa832667656ad7 (diff)
downloadskyblock-api-74c078392c46405a8432309c8672dc09642956d6.tar.gz
skyblock-api-74c078392c46405a8432309c8672dc09642956d6.tar.bz2
skyblock-api-74c078392c46405a8432309c8672dc09642956d6.zip
change profileCache to use clones
Diffstat (limited to 'src')
-rw-r--r--src/cleaners/skyblock/collections.ts2
-rw-r--r--src/hypixelCached.ts12
2 files changed, 12 insertions, 2 deletions
diff --git a/src/cleaners/skyblock/collections.ts b/src/cleaners/skyblock/collections.ts
index 3b1a178..a3e1fb3 100644
--- a/src/cleaners/skyblock/collections.ts
+++ b/src/cleaners/skyblock/collections.ts
@@ -1,4 +1,4 @@
-import { cleanItemId, cleanItemNames, hypixelItemNames } from "./itemId"
+import { cleanItemId, hypixelItemNames } from "./itemId"
const COLLECTIONS = {
'farming': [
diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts
index ae544a2..e311fe6 100644
--- a/src/hypixelCached.ts
+++ b/src/hypixelCached.ts
@@ -10,6 +10,10 @@ import { undashUuid } from './util'
import { CleanProfile, CleanFullProfile, CleanBasicProfile } from './cleaners/skyblock/profile'
+// TODO: put this somewhere else
+const debug = false
+
+
// cache usernames for 4 hours
const usernameCache = new NodeCache({
stdTTL: 60 * 60 * 4,
@@ -32,7 +36,7 @@ const playerCache = new NodeCache({
const profileCache = new NodeCache({
stdTTL: 30,
checkperiod: 10,
- useClones: false,
+ useClones: true,
})
const profilesCache = new NodeCache({
@@ -79,6 +83,7 @@ export async function uuidFromUser(user: string): Promise<string> {
*/
export async function usernameFromUser(user: string): Promise<string> {
if (usernameCache.has(undashUuid(user))) {
+ if (debug) console.log('Cache hit! usernameFromUser', user)
return usernameCache.get(undashUuid(user))
}
@@ -93,6 +98,7 @@ export async function fetchPlayer(user: string): Promise<CleanPlayer> {
const playerUuid = await uuidFromUser(user)
if (playerCache.has(playerUuid)) {
+ if (debug) console.log('Cache hit! fetchPlayer', playerUuid)
return playerCache.get(playerUuid)
}
@@ -112,6 +118,7 @@ export async function fetchPlayer(user: string): Promise<CleanPlayer> {
export async function fetchSkyblockProfiles(playerUuid: string): Promise<CleanProfile[]> {
if (profilesCache.has(playerUuid)) {
+ if (debug) console.log('Cache hit! fetchSkyblockProfiles', playerUuid)
return profilesCache.get(playerUuid)
}
@@ -157,6 +164,7 @@ export async function fetchSkyblockProfiles(playerUuid: string): Promise<CleanPr
async function fetchBasicProfiles(user: string): Promise<CleanBasicProfile[]> {
const playerUuid = await uuidFromUser(user)
if (basicProfilesCache.has(playerUuid)) {
+ if (debug) console.log('Cache hit! fetchBasicProfiles', playerUuid)
return basicProfilesCache.get(playerUuid)
}
const player = await fetchPlayer(playerUuid)
@@ -202,6 +210,7 @@ export async function fetchProfile(user: string, profile: string): Promise<Clean
if (profileCache.has(profileUuid)) {
// we have the profile cached, return it :)
+ if (debug) console.log('Cache hit! fetchProfile', profileUuid)
return profileCache.get(profileUuid)
}
@@ -236,6 +245,7 @@ export async function fetchProfileName(user: string, profile: string): Promise<s
if (profileNameCache.has(`${playerUuid}.${profileUuid}`)) {
// Return the profile name if it's cached
+ if (debug) console.log('Cache hit! fetchProfileName', profileUuid)
return profileNameCache.get(`${playerUuid}.${profileUuid}`)
}