From d67beb8dbfe430130544d8377237453faeccb3fd Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 11 Sep 2023 14:27:11 +0100 Subject: [PATCH] Cache zap parser results --- packages/system/src/zaps.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/system/src/zaps.ts b/packages/system/src/zaps.ts index 57c3b355..ee22cb15 100644 --- a/packages/system/src/zaps.ts +++ b/packages/system/src/zaps.ts @@ -4,6 +4,8 @@ import { HexKey, NostrEvent } from "./nostr"; import { findTag } from "./utils"; import { MetadataCache } from "./cache"; +const ParsedZapCache = new Map(); + function getInvoice(zap: NostrEvent): InvoiceDetails | undefined { const bolt11 = findTag(zap, "bolt11"); if (!bolt11) { @@ -13,6 +15,11 @@ function getInvoice(zap: NostrEvent): InvoiceDetails | undefined { } export function parseZap(zapReceipt: NostrEvent, userCache: FeedCache, refNote?: NostrEvent): ParsedZap { + const existing = ParsedZapCache.get(zapReceipt.id); + if(existing) { + return existing; + } + let innerZapJson = findTag(zapReceipt, "description"); if (innerZapJson) { try { @@ -67,7 +74,7 @@ export function parseZap(zapReceipt: NostrEvent, userCache: FeedCache