From 4d0ee8736bc327782d690392aa552c2a848a9a4e Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Thu, 1 Dec 2022 22:47:57 +0100 Subject: [PATCH] Reduce amount of server requests to fetch remote avatars --- plugins/avatars/avatars.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/avatars/avatars.js b/plugins/avatars/avatars.js index a433234bb..501fdfae8 100644 --- a/plugins/avatars/avatars.js +++ b/plugins/avatars/avatars.js @@ -37,17 +37,20 @@ runQueue = (() => { let item = queue.shift(); while (item) { - let url = getAvatar(item[0]); + let url = getAvatar(item[0]), + uid = getAvatarUid(item[0]); if (url) { item[1](url); item = queue.shift(); - } else { + } else if (!avatars.has(uid)) { let from = item[0].from[0]; rl.pluginRemoteRequest((iError, data) => { if (!iError && data?.Result.type) { url = `data:${data.Result.type};base64,${data.Result.data}`; - avatars.set(getAvatarUid(item[0]), url); + avatars.set(uid, url); item[1](url); + } else { + avatars.set(uid, ''); } runQueue(); }, 'Avatar', { @@ -55,6 +58,9 @@ email: from.email }); break; + } else { + runQueue(); + break; } } }).debounce(1000);