Elffuss BraidHub

kikocis/osiris public

perf: drastically reduce client polling rates and disable background fetching to save Vercel costs
Changeseta1d3189fba30c78e9dca3f29e0a5df029f35021e32d49e114eea9db4a34f2cee
AuthorGemini CLI <gemini@example.com> · 2026-05-23 21:52 -04:00
CommitterGemini CLI <gemini@example.com> · 2026-05-23 21:52 -04:00
Parentsc867dff8b92f

Browse the files at this changeset

1 file changed

modified src/app/page.tsx +4 −3
@@ -244,6 +244,7 @@
244244
245245 // ── SHARED FETCH UTILITY (Fixes #107 — single definition, not 3 copies) ──
246246 const fetchEndpoint = useCallback(async (url: string, transform?: (d: any) => any, options?: RequestInit) => {
247+ if (typeof document !== 'undefined' && document.hidden) return;
247248 try {
248249 const res = await fetch(url, options);
249250 if (res.ok) {
@@ -359,13 +360,13 @@
359360 }
360361
361362 if (activeLayers.balloons) {
362- intervals.push(setInterval(() => fetchEndpoint('/api/balloons', d => ({ balloons: d.balloons })), 30000)); // 30s
363+ intervals.push(setInterval(() => fetchEndpoint('/api/balloons', d => ({ balloons: d.balloons })), 300000)); // 5m
363364 }
364365 if (activeLayers.radiation) {
365- intervals.push(setInterval(() => fetchEndpoint('/api/radiation', d => ({ radiation: d.stations })), 60000)); // 1m
366+ intervals.push(setInterval(() => fetchEndpoint('/api/radiation', d => ({ radiation: d.stations })), 300000)); // 5m
366367 }
367368 if (activeLayers.maritime) {
368- intervals.push(setInterval(() => fetchEndpoint('/api/maritime', d => ({ maritime_ports: d.ports, maritime_chokepoints: d.chokepoints, maritime_ships: d.ships })), 10000)); // 10s
369+ intervals.push(setInterval(() => fetchEndpoint('/api/maritime', d => ({ maritime_ports: d.ports, maritime_chokepoints: d.chokepoints, maritime_ships: d.ships })), 60000)); // 1m
369370 }
370371 // Fires: no polling needed (data changes very slowly, initial fetch is enough)
371372 return () => intervals.forEach(clearInterval);