diff --git a/src/views/events.js b/src/views/events.js index bd8a0f1..5f81c02 100644 --- a/src/views/events.js +++ b/src/views/events.js @@ -1,14 +1,21 @@ import { esc } from '../utils.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) { const base = S.cfg?.backendUrl; if(!base) return []; + const hit = _cache.get(artistName); + if(hit && Date.now() - hit.ts < _TTL) return hit.data; try { const r = await fetch(`${base}/api/events/${encodeURIComponent(artistName)}`); if(!r.ok) return []; const data = await r.json(); if(!Array.isArray(data)) return []; + _cache.set(artistName, { ts: Date.now(), data }); return data; } catch { return []; } }