diff options
Diffstat (limited to 'src/nostr.js')
| -rw-r--r-- | src/nostr.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/nostr.js b/src/nostr.js index e414d57..b76e865 100644 --- a/src/nostr.js +++ b/src/nostr.js @@ -466,7 +466,16 @@ export function parseNostrPubkey(input) { return null; } // An npub or 64-hex nostr pubkey → hex, or null if it isn't one. -export function npubOf(pkHex) { try { return npubEncode(pkHex); } catch { return null; } } +// Memoized: the feed asks for the reader's npub thousands of times while it +// filters rows, and bech32 encoding was the top self time of a scroll. +const npubMemo = new Map(); +export function npubOf(pkHex) { + if (npubMemo.has(pkHex)) return npubMemo.get(pkHex); + let v = null; try { v = npubEncode(pkHex); } catch {} + if (npubMemo.size > 4000) npubMemo.clear(); + npubMemo.set(pkHex, v); + return v; +} // An event reference other clients can resolve: the id plus who wrote it, so // a quote can be fetched even by someone who doesn't have it yet. export function neventOf(id, author) { try { return neventEncode({ id, author }); } catch { return null; } } |
