Skip to content

Commit

Permalink
Cache avatars based on just type and id (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesan authored Nov 29, 2023
1 parent 94503ff commit c9f3739
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils/notification/notificationAvatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> => {
async (em: EntityManager, type: 'channelId' | 'membershipId', id: string): Promise<string> => {
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

Expand All @@ -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
Expand All @@ -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}`
)

0 comments on commit c9f3739

Please sign in to comment.