Speedup identicons by caching them

This commit is contained in:
the-djmaze 2024-10-29 01:20:34 +01:00
parent 490d808cdb
commit 8645b0ab1e

View file

@ -38,6 +38,7 @@
queue = [], queue = [],
avatars = new Map, avatars = new Map,
ncAvatars = new Map, ncAvatars = new Map,
identicons = new Map,
templateId = 'MailMessageView', templateId = 'MailMessageView',
b64 = data => btoa(unescape(encodeURIComponent(data))), b64 = data => btoa(unescape(encodeURIComponent(data))),
b64url = data => b64(data).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''), b64url = data => b64(data).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''),
@ -78,15 +79,22 @@
(from.name?.split(/[^\p{L}]+/gu) || []).reduce((a, s) => a + (s[0] || ''), '') (from.name?.split(/[^\p{L}]+/gu) || []).reduce((a, s) => a + (s[0] || ''), '')
.slice(0,2) .slice(0,2)
.toUpperCase(), .toUpperCase(),
setIdenticon = (msg, fn) => hash(msg.from[0].email).then(hash => { setIdenticon = (msg, fn) => {
const uri = 'data:image/svg+xml;base64,' + b64(window.identiconSvg( const from = email(msg);
hash, if (identicons.get(from)) {
fromChars(msg.from[0]), fn(identicons.get(from));
window.getComputedStyle(getEl('rl-app'), null).getPropertyValue('font-family') } else {
)); hash(from).then(hash => {
// avatars.set(getAvatarUid(msg), uri); const uri = 'data:image/svg+xml;base64,' + b64(window.identiconSvg(
fn(uri); hash,
}), fromChars(msg.from[0]),
window.getComputedStyle(getEl('rl-app'), null).getPropertyValue('font-family')
));
identicons.set(email(msg), uri);
fn(uri);
});
}
},
addQueue = (msg, fn) => { addQueue = (msg, fn) => {
if (msg.from?.[0]) { if (msg.from?.[0]) {