mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-27 01:04:19 +01:00
Cache the LNURL response
This commit is contained in:
@@ -1,4 +1,24 @@
|
||||
import { LNURL } from '@/deps.ts';
|
||||
import { Debug, LNURL, type LNURLDetails } from '@/deps.ts';
|
||||
import { SimpleLRU } from '@/utils/SimpleLRU.ts';
|
||||
import { Time } from '@/utils/time.ts';
|
||||
import { fetchWorker } from '@/workers/fetch.ts';
|
||||
|
||||
const debug = Debug('ditto:lnurl');
|
||||
|
||||
const lnurlCache = new SimpleLRU<string, LNURLDetails>(
|
||||
async (lnurl, { signal }) => {
|
||||
debug(`Lookup ${lnurl}`);
|
||||
try {
|
||||
const result = await LNURL.lookup(lnurl, { fetch: fetchWorker, signal });
|
||||
debug(`Found: ${lnurl}`);
|
||||
return result;
|
||||
} catch (e) {
|
||||
debug(`Not found: ${lnurl}`);
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
{ max: 1000, ttl: Time.minutes(30) },
|
||||
);
|
||||
|
||||
/** Get an LNURL from a lud06 or lud16. */
|
||||
function getLnurl({ lud06, lud16 }: { lud06?: string; lud16?: string }, limit?: number): string | undefined {
|
||||
@@ -12,4 +32,4 @@ function getLnurl({ lud06, lud16 }: { lud06?: string; lud16?: string }, limit?:
|
||||
}
|
||||
}
|
||||
|
||||
export { getLnurl };
|
||||
export { getLnurl, lnurlCache };
|
||||
|
||||
Reference in New Issue
Block a user