From 4e6fec43d3f6ba1b2be433c59d29866624fe2610 Mon Sep 17 00:00:00 2001 From: kamaji Date: Sat, 7 Feb 2026 16:13:38 -0600 Subject: [PATCH] Fix queue list not updating: restore fast polling alongside events The previous change extended the poll from 5s to 30s relying on photo-updated events, but the service worker may still serve the old storage.js without event dispatch, leaving the list stale. Now polls every 3s while there are active uploads (pending/uploading), 15s fallback when idle, plus event-based refresh as a bonus. Co-Authored-By: Claude Opus 4.6 --- app/static/sw.js | 6 +++--- app/templates/queue.html | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/static/sw.js b/app/static/sw.js index e6b5724..6b0a85d 100644 --- a/app/static/sw.js +++ b/app/static/sw.js @@ -1,9 +1,9 @@ // NextSnap Service Worker // Provides offline-first caching for the app shell -const CACHE_VERSION = 'nextsnap-v16'; -const APP_SHELL_CACHE = 'nextsnap-shell-v12'; -const RUNTIME_CACHE = 'nextsnap-runtime-v12'; +const CACHE_VERSION = 'nextsnap-v17'; +const APP_SHELL_CACHE = 'nextsnap-shell-v13'; +const RUNTIME_CACHE = 'nextsnap-runtime-v13'; // Assets to cache on install const APP_SHELL_ASSETS = [ diff --git a/app/templates/queue.html b/app/templates/queue.html index 7d33d26..9d95fd4 100644 --- a/app/templates/queue.html +++ b/app/templates/queue.html @@ -434,7 +434,8 @@ async function loadQueue() { } } - document.getElementById('sync-now-btn').disabled = activePhotos.length === 0 || !navigator.onLine; + hasActiveUploads = activePhotos.length > 0; + document.getElementById('sync-now-btn').disabled = !hasActiveUploads || !navigator.onLine; } function createQueueItem(photo, isCompleted) { @@ -616,21 +617,29 @@ window.addEventListener('offline', () => { // Live updates: listen for photo status changes from the sync engine let refreshTimer = null; -window.addEventListener('photo-updated', () => { - // Debounce: rapid status transitions (pending→uploading→verified) - // would otherwise trigger multiple full rebuilds +function scheduleRefresh() { if (refreshTimer) clearTimeout(refreshTimer); refreshTimer = setTimeout(() => { refreshTimer = null; loadQueue(); updateStats(); }, 300); -}); +} +window.addEventListener('photo-updated', scheduleRefresh); -// Fallback: full refresh every 30s in case events are missed +// Poll every 3s while uploads are active, 15s when idle +let hasActiveUploads = true; // assume active until first check +setInterval(() => { + if (hasActiveUploads) { + loadQueue(); + updateStats(); + } +}, 3000); + +// Slower fallback poll for idle state setInterval(() => { loadQueue(); updateStats(); -}, 30000); +}, 15000); {% endblock %}