From cb63f489e47941b513cd9a0a77fdba99dc00a1a3 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Tue, 26 Jan 2021 17:03:43 +0000 Subject: [PATCH] Cache player heads by both account and size --- src/util.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/util.ts b/src/util.ts index 54d0621..3eb064d 100644 --- a/src/util.ts +++ b/src/util.ts @@ -39,21 +39,22 @@ export default { }, getMinecraftHead(player: DynmapPlayer | string, size: string): Promise { - const account = typeof player === 'string' ? player : player.account; + const account = typeof player === 'string' ? player : player.account, + cacheKey = `${account}-${size}`; - if(headCache.has(account)) { - return Promise.resolve(headCache.get(account) as HTMLImageElement); + if(headCache.has(cacheKey)) { + return Promise.resolve(headCache.get(cacheKey) as HTMLImageElement); } - if(headUnresolvedCache.has(account)) { - return headUnresolvedCache.get(account) as Promise; + if(headUnresolvedCache.has(cacheKey)) { + return headUnresolvedCache.get(cacheKey) as Promise; } const promise = new Promise((resolve, reject) => { const faceImage = new Image(); faceImage.onload = function() { - headCache.set(account, faceImage); + headCache.set(cacheKey, faceImage); resolve(faceImage); }; @@ -64,9 +65,9 @@ export default { const src = (size === 'body') ? `faces/body/${account}.png` :`faces/${size}x${size}/${account}.png`; faceImage.src = this.concatURL(window.config.url.markers, src); - }).finally(() => headUnresolvedCache.delete(account)) as Promise; + }).finally(() => headUnresolvedCache.delete(cacheKey)) as Promise; - headUnresolvedCache.set(account, promise); + headUnresolvedCache.set(cacheKey, promise); return promise; },