From c9f373900bd7e8b86985cf01bda033a34544f4df Mon Sep 17 00:00:00 2001 From: Theophile Sandoz Date: Wed, 29 Nov 2023 13:52:28 +0100 Subject: [PATCH] Cache avatars based on just type and id (#259) --- src/utils/notification/notificationAvatars.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/notification/notificationAvatars.ts b/src/utils/notification/notificationAvatars.ts index 40d3ba41e..103668048 100644 --- a/src/utils/notification/notificationAvatars.ts +++ b/src/utils/notification/notificationAvatars.ts @@ -6,10 +6,10 @@ import { getAssetUrls } from '../../server-extension/resolvers/AssetsResolver/ut import { ConfigVariable, config } from '../config' export const getNotificationAvatar = memoize( - async (em: EntityManager, type: 'channelId' | 'membershipId', param: string): Promise => { + async (em: EntityManager, type: 'channelId' | 'membershipId', id: string): Promise => { switch (type) { case 'channelId': { - const channel = await em.getRepository(Channel).findOneBy({ id: param }) + const channel = await em.getRepository(Channel).findOneBy({ id }) const objectId = channel?.avatarPhotoId if (!objectId) break @@ -21,7 +21,7 @@ export const getNotificationAvatar = memoize( } case 'membershipId': { - const member = await em.getRepository(MemberMetadata).findOneBy({ id: param }) + const member = await em.getRepository(MemberMetadata).findOneBy({ id }) const avatar = member?.avatar // AvatarObject is not yet supported @@ -34,5 +34,6 @@ export const getNotificationAvatar = memoize( // Fallback to a placeholder const notificationAssetRoot = await config.get(ConfigVariable.AppAssetStorage, em) return `${notificationAssetRoot}/placeholder/avatar.png` - } + }, + (_, type, id) => `${type}:${id}` )