Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Cache avatars based on just type and id #259

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`
)
Loading