perf: add deriveDedupedProfile to cache profile store instances by pubkey
This commit is contained in:
@@ -147,6 +147,7 @@ import {
|
|||||||
makeUserData,
|
makeUserData,
|
||||||
makeUserLoader,
|
makeUserLoader,
|
||||||
manageRelay,
|
manageRelay,
|
||||||
|
deriveProfile,
|
||||||
displayProfileByPubkey,
|
displayProfileByPubkey,
|
||||||
getProfile,
|
getProfile,
|
||||||
} from "@welshman/app"
|
} from "@welshman/app"
|
||||||
@@ -155,6 +156,25 @@ import {readFeed} from "@lib/feeds"
|
|||||||
|
|
||||||
export const fromCsv = (s: string) => (s || "").split(",").filter(identity)
|
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 ROOM = "h"
|
||||||
|
|
||||||
export const PROTECTED = ["-"]
|
export const PROTECTED = ["-"]
|
||||||
|
|||||||
Reference in New Issue
Block a user