Cache zap parser results

This commit is contained in:
Kieran 2023-09-11 14:27:11 +01:00
parent 3e0fae2c33
commit d67beb8dbf
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
1 changed files with 10 additions and 1 deletions

View File

@ -4,6 +4,8 @@ import { HexKey, NostrEvent } from "./nostr";
import { findTag } from "./utils";
import { MetadataCache } from "./cache";
const ParsedZapCache = new Map<string, ParsedZap>();
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<MetadataCache>, 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<MetadataCa
// ignored: console.debug("Invalid zap", zapReceipt, e);
}
}
return {
const ret = {
id: zapReceipt.id,
zapService: zapReceipt.pubkey,
amount: 0,
@ -75,6 +82,8 @@ export function parseZap(zapReceipt: NostrEvent, userCache: FeedCache<MetadataCa
anonZap: false,
errors: ["invalid zap, parsing failed"],
};
ParsedZapCache.set(ret.id, ret);
return ret;
}
export interface ParsedZap {