Cache zap parser results
This commit is contained in:
parent
3e0fae2c33
commit
d67beb8dbf
@ -4,6 +4,8 @@ import { HexKey, NostrEvent } from "./nostr";
|
|||||||
import { findTag } from "./utils";
|
import { findTag } from "./utils";
|
||||||
import { MetadataCache } from "./cache";
|
import { MetadataCache } from "./cache";
|
||||||
|
|
||||||
|
const ParsedZapCache = new Map<string, ParsedZap>();
|
||||||
|
|
||||||
function getInvoice(zap: NostrEvent): InvoiceDetails | undefined {
|
function getInvoice(zap: NostrEvent): InvoiceDetails | undefined {
|
||||||
const bolt11 = findTag(zap, "bolt11");
|
const bolt11 = findTag(zap, "bolt11");
|
||||||
if (!bolt11) {
|
if (!bolt11) {
|
||||||
@ -13,6 +15,11 @@ function getInvoice(zap: NostrEvent): InvoiceDetails | undefined {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function parseZap(zapReceipt: NostrEvent, userCache: FeedCache<MetadataCache>, refNote?: NostrEvent): ParsedZap {
|
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");
|
let innerZapJson = findTag(zapReceipt, "description");
|
||||||
if (innerZapJson) {
|
if (innerZapJson) {
|
||||||
try {
|
try {
|
||||||
@ -67,7 +74,7 @@ export function parseZap(zapReceipt: NostrEvent, userCache: FeedCache<MetadataCa
|
|||||||
// ignored: console.debug("Invalid zap", zapReceipt, e);
|
// ignored: console.debug("Invalid zap", zapReceipt, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
const ret = {
|
||||||
id: zapReceipt.id,
|
id: zapReceipt.id,
|
||||||
zapService: zapReceipt.pubkey,
|
zapService: zapReceipt.pubkey,
|
||||||
amount: 0,
|
amount: 0,
|
||||||
@ -75,6 +82,8 @@ export function parseZap(zapReceipt: NostrEvent, userCache: FeedCache<MetadataCa
|
|||||||
anonZap: false,
|
anonZap: false,
|
||||||
errors: ["invalid zap, parsing failed"],
|
errors: ["invalid zap, parsing failed"],
|
||||||
};
|
};
|
||||||
|
ParsedZapCache.set(ret.id, ret);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ParsedZap {
|
export interface ParsedZap {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user