perf: add deriveDedupedProfile to cache profile store instances by pubkey

This commit is contained in:
2026-04-30 14:25:16 +05:30
parent 976ccdabd4
commit 6f82485200
+20
View File
@@ -147,6 +147,7 @@ import {
makeUserData,
makeUserLoader,
manageRelay,
deriveProfile,
displayProfileByPubkey,
getProfile,
} from "@welshman/app"
@@ -155,6 +156,25 @@ import {readFeed} from "@lib/feeds"
export const fromCsv = (s: string) => (s || "").split(",").filter(identity)
const profileStoreCache = new Map<string, ReturnType<typeof deriveProfile>>()
export const deriveDedupedProfile = (
...args: Parameters<typeof deriveProfile>
): ReturnType<typeof deriveProfile> => {
const key = JSON.stringify(args)
const cached = profileStoreCache.get(key)
if (cached) {
return cached
}
const store = deriveProfile(...args)
profileStoreCache.set(key, store)
return store
}
export const ROOM = "h"
export const PROTECTED = ["-"]