perf: cache Ticketmaster event results for 30 min per artist

Avoids burning API quota on repeat visits to the same artist page.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-06-08 20:52:50 +02:00
1 parent adcbb2e883
commit 2c9d3a9dde
1 file changed
+7
+7
View File
@@ -1,14 +1,21 @@
import { esc } from '../utils.js'; import { esc } from '../utils.js';
import { S } from '../state.js'; import { S } from '../state.js';
// Cache results for the session — keyed by artist name, expires after 30 min.
const _cache = new Map(); // name → { ts, data }
const _TTL = 30 * 60 * 1000;
export async function fetchEvents(artistName) { export async function fetchEvents(artistName) {
const base = S.cfg?.backendUrl; const base = S.cfg?.backendUrl;
if(!base) return []; if(!base) return [];
const hit = _cache.get(artistName);
if(hit && Date.now() - hit.ts < _TTL) return hit.data;
try { try {
const r = await fetch(`${base}/api/events/${encodeURIComponent(artistName)}`); const r = await fetch(`${base}/api/events/${encodeURIComponent(artistName)}`);
if(!r.ok) return []; if(!r.ok) return [];
const data = await r.json(); const data = await r.json();
if(!Array.isArray(data)) return []; if(!Array.isArray(data)) return [];
_cache.set(artistName, { ts: Date.now(), data });
return data; return data;
} catch { return []; } } catch { return []; }
} }