Cache player heads by both account and size
This commit is contained in:
parent
a966812f1a
commit
cb63f489e4
17
src/util.ts
17
src/util.ts
@ -39,21 +39,22 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getMinecraftHead(player: DynmapPlayer | string, size: string): Promise<HTMLImageElement> {
|
getMinecraftHead(player: DynmapPlayer | string, size: string): Promise<HTMLImageElement> {
|
||||||
const account = typeof player === 'string' ? player : player.account;
|
const account = typeof player === 'string' ? player : player.account,
|
||||||
|
cacheKey = `${account}-${size}`;
|
||||||
|
|
||||||
if(headCache.has(account)) {
|
if(headCache.has(cacheKey)) {
|
||||||
return Promise.resolve(headCache.get(account) as HTMLImageElement);
|
return Promise.resolve(headCache.get(cacheKey) as HTMLImageElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(headUnresolvedCache.has(account)) {
|
if(headUnresolvedCache.has(cacheKey)) {
|
||||||
return headUnresolvedCache.get(account) as Promise<HTMLImageElement>;
|
return headUnresolvedCache.get(cacheKey) as Promise<HTMLImageElement>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const promise = new Promise((resolve, reject) => {
|
const promise = new Promise((resolve, reject) => {
|
||||||
const faceImage = new Image();
|
const faceImage = new Image();
|
||||||
|
|
||||||
faceImage.onload = function() {
|
faceImage.onload = function() {
|
||||||
headCache.set(account, faceImage);
|
headCache.set(cacheKey, faceImage);
|
||||||
resolve(faceImage);
|
resolve(faceImage);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -64,9 +65,9 @@ export default {
|
|||||||
|
|
||||||
const src = (size === 'body') ? `faces/body/${account}.png` :`faces/${size}x${size}/${account}.png`;
|
const src = (size === 'body') ? `faces/body/${account}.png` :`faces/${size}x${size}/${account}.png`;
|
||||||
faceImage.src = this.concatURL(window.config.url.markers, src);
|
faceImage.src = this.concatURL(window.config.url.markers, src);
|
||||||
}).finally(() => headUnresolvedCache.delete(account)) as Promise<HTMLImageElement>;
|
}).finally(() => headUnresolvedCache.delete(cacheKey)) as Promise<HTMLImageElement>;
|
||||||
|
|
||||||
headUnresolvedCache.set(account, promise);
|
headUnresolvedCache.set(cacheKey, promise);
|
||||||
|
|
||||||
return promise;
|
return promise;
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user