feat: add non-blocking datastore refresh with dedicated lock and improve service worker offline handling

Add datastore_refresh_lock to prevent concurrent refresh operations. Extract refresh_datastore_storage() function with non-blocking lock acquisition using acquire(blocking=False). Update datastore_snapshot() to spawn background thread for refresh when cache is stale but return immediately with cached data. Add offline fallback HTML page to service worker for navigate requests with 503 status for
This commit is contained in:
2026-08-21 20:55:19 +02:00
parent 1882d4e137
commit 5d7e452aaf
3 changed files with 30 additions and 10 deletions
+7 -2
View File
@@ -1,4 +1,4 @@
const CACHE_NAME = 'media-max-shell-v5';
const CACHE_NAME = 'media-max-shell-v6';
const SHELL = ['/static/media-mark.svg', '/static/media-mark-192.png', '/static/media-mark-512.png', '/static/manifest.json'];
self.addEventListener('install', event => {
@@ -16,5 +16,10 @@ self.addEventListener('fetch', event => {
if (request.method !== 'GET') return;
const url = new URL(request.url);
if (url.pathname.startsWith('/api/')) return;
event.respondWith(fetch(request).catch(() => caches.match(request).then(response => response || caches.match('/static/manifest.json'))));
event.respondWith(fetch(request).catch(() => {
if (request.mode === 'navigate') {
return new Response('<!doctype html><meta charset="utf-8"><title>Media Max</title><style>body{margin:0;padding:2rem;background:#181818;color:#ddd;font:16px system-ui}main{max-width:36rem;margin:auto}h1{color:#f4c430}</style><main><h1>Media Max</h1><p>Die Verbindung ist momentan unterbrochen. Bitte erneut laden.</p></main>', {headers: {'Content-Type': 'text/html; charset=utf-8'}});
}
return caches.match(request).then(response => response || new Response('', {status: 503}));
}));
});