diff options
author | mat <github@matdoes.dev> | 2021-10-03 12:08:41 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2021-10-03 12:08:41 -0500 |
commit | 7afe165979419f1fd96f6356f32ded35cb143de9 (patch) | |
tree | 9fd58fb5721804c1f470e7ae0ac13e7eb37b3d27 /src/hypixelCached.ts | |
parent | 1291f0f32b6f626666b6fb86b8d87e3c4293cb7c (diff) | |
download | skyblock-api-7afe165979419f1fd96f6356f32ded35cb143de9.tar.gz skyblock-api-7afe165979419f1fd96f6356f32ded35cb143de9.tar.bz2 skyblock-api-7afe165979419f1fd96f6356f32ded35cb143de9.zip |
attempt to fix memory leak
Diffstat (limited to 'src/hypixelCached.ts')
-rw-r--r-- | src/hypixelCached.ts | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts index 07566f9..a80f4d2 100644 --- a/src/hypixelCached.ts +++ b/src/hypixelCached.ts @@ -10,7 +10,7 @@ import * as mojang from './mojang.js' import NodeCache from 'node-cache' import { debug } from './index.js' import LRUCache from 'lru-cache' -import { TLSSocket } from 'tls' +// import { TLSSocket } from 'tls' // cache usernames for 30 minutes /** uuid: username */ @@ -22,9 +22,9 @@ export const usernameCache = new NodeCache({ useClones: false, }) -usernameCache.setMaxListeners(50) -// @ts-ignore for some reason the typings don't have setMaxListeners but it does -TLSSocket.setMaxListeners(50) +// usernameCache.setMaxListeners(50) +// // @ts-ignore for some reason the typings don't have setMaxListeners but it does +// TLSSocket.setMaxListeners(50) export const basicProfilesCache = new NodeCache({ @@ -107,8 +107,8 @@ export async function uuidFromUser(user: string): Promise<string | undefined> { } // check if the username is a value - const uuidToUsername: { [ key: string ]: string | Promise<KeyValue> } = usernameCache.mget(usernameCache.keys()) - for (const [ uuid, username ] of Object.entries(uuidToUsername)) { + const uuidToUsername: { [key: string]: string | Promise<KeyValue> } = usernameCache.mget(usernameCache.keys()) + for (const [uuid, username] of Object.entries(uuidToUsername)) { if (username && (<string>username).toLowerCase && user.toLowerCase() === (<string>username).toLowerCase()) return uuid } @@ -119,7 +119,7 @@ export async function uuidFromUser(user: string): Promise<string | undefined> { // set it as waitForCacheSet (a promise) in case uuidFromUser gets called while its fetching mojang usernameCache.set(undashedUser, waitForCacheSet(usernameCache, user, user)) - + // not cached, actually fetch mojang api now let { uuid, username } = await mojang.profileFromUser(user) if (!uuid) { @@ -186,7 +186,7 @@ export async function fetchPlayer(user: string): Promise<CleanPlayer | null> { // clone in case it gets modified somehow later playerCache.set(playerUuid, cleanPlayer) usernameCache.set(playerUuid, cleanPlayer.username) - + const cleanBasicPlayer = Object.assign({}, cleanPlayer) delete cleanBasicPlayer.profiles basicPlayerCache.set(playerUuid, cleanBasicPlayer) @@ -202,7 +202,7 @@ export async function fetchBasicPlayer(user: string): Promise<CleanPlayer | null if (basicPlayerCache.has(playerUuid)) return basicPlayerCache.get(playerUuid)! - + const player = await fetchPlayer(playerUuid) if (!player) { console.debug('no player? this should never happen, perhaps the uuid is invalid or the player hasn\'t played hypixel', playerUuid) @@ -390,7 +390,7 @@ export async function fetchProfileName(user: string, profile: string): Promise<s if (debug) console.debug('Cache miss: fetchProfileName', user, profile) const basicProfiles = await fetchBasicProfiles(playerUuid) - + if (!basicProfiles) return null let profileName: string | null = null |