Add invocation counter and logging to track fetch calls in getMentionsFor function
All checks were successful
Deploy / deploy (push) Successful in 1m16s

This commit is contained in:
Adrian Altner 2026-04-22 02:13:39 +02:00
parent c4e12619a1
commit fb59d20200

View file

@ -40,7 +40,7 @@ interface WMResponse {
const API = 'https://webmention.io/api/mentions.jf2';
const perTargetCache = new Map<string, WMEntry[]>();
let invocationCounter = 0;
async function fetchForTarget(target: string): Promise<WMEntry[]> {
const token = import.meta.env.WEBMENTION_TOKEN;
@ -73,8 +73,8 @@ export async function getMentionsFor(target: string | URL): Promise<WMEntry[]> {
const withSlash = canonical.endsWith('/') ? canonical : `${canonical}/`;
const withoutSlash = canonical.replace(/\/+$/, '');
const cached = perTargetCache.get(canonical);
if (cached) return cached;
const invocation = ++invocationCounter;
console.log(`[webmentions getMentionsFor #${invocation}] target=${canonical}`);
const [a, b] = await Promise.all([fetchForTarget(withSlash), fetchForTarget(withoutSlash)]);
const seen = new Set<number>();
@ -86,7 +86,7 @@ export async function getMentionsFor(target: string | URL): Promise<WMEntry[]> {
merged.push(m);
}
perTargetCache.set(canonical, merged);
console.log(`[webmentions getMentionsFor #${invocation}] returning ${merged.length} mentions for ${canonical}`);
return merged;
}