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:
1 parent
adcbb2e883
commit
2c9d3a9dde
1 file changed
+7
@@ -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 []; }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user