Perf: 9 Performance-Fixes — SW by-v1072
Backend: - DB: 3 neue Indizes (forum_posts thread+user, routes user) — Forum/Routen-Queries - Caching: cache.py (TTL-Cache ohne neue Dependency) für 5 statische Listen (training_exercises, pflege_tipps, wiki_stats, wiki_gruppen, help_articles) - diary.py + breeder_photos.py: Bildverarbeitung (ffmpeg/PIL/EXIF) per run_in_executor → blockiert Event-Loop nicht mehr - scheduler.py: 11 kollidierende Jobs auf 5-Min-Intervalle gestaggert, coalesce=True - social.py: ORDER BY RANDOM() ohne LIMIT in 2 Stellen gefixt - alerts.py: Haversine-Loop bekommt SQL-Bounding-Box-Vorfilter Frontend: - sw.js: Tile-Cache mit LRU-Eviction (max 500 Einträge) - admin.js: Event-Listener-Leak — Tab-Klicks per Delegation statt N Listener - api.js: compressImage() Helper — Client-seitiges Resize auf max 2000px (HEIC/Videos/<500KB unverändert), integriert in 8 Upload-Stellen (diary, dog-profile×2, walks, poison, lost, health×2) Bump APP_VER 1071 → 1072 (sw.js, app.js, main.py, index.html)
This commit is contained in:
parent
3abf974d29
commit
c03884cb81
23 changed files with 461 additions and 120 deletions
|
|
@ -4,7 +4,7 @@
|
|||
============================================================ */
|
||||
|
||||
// ← EINZIGE Stelle für die Version — STATIC_ASSETS und CACHE_VERSION leiten sich ab
|
||||
const VER = '1071';
|
||||
const VER = '1072';
|
||||
const CACHE_VERSION = `by-v${VER}`;
|
||||
const CACHE_STATIC = `${CACHE_VERSION}-static`;
|
||||
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten
|
||||
|
|
@ -132,6 +132,26 @@ function _isMediaUpload(request) {
|
|||
return (request.headers.get('Content-Type') || '').includes('multipart');
|
||||
}
|
||||
|
||||
// Tile-Cache LRU: Eviction wenn zu viele Tiles drin sind
|
||||
// cache.keys() liefert Insertion-Order — daher löschen wir vom Anfang.
|
||||
// Bei jedem Tile-Add: trimTileCache() im Hintergrund (kein await vor respondWith).
|
||||
const _TILE_MAX_ENTRIES = 500;
|
||||
let _tileTrimRunning = false;
|
||||
async function trimTileCache(maxEntries = _TILE_MAX_ENTRIES) {
|
||||
if (_tileTrimRunning) return; // gleichzeitige Trims verhindern
|
||||
_tileTrimRunning = true;
|
||||
try {
|
||||
const cache = await caches.open(CACHE_TILES);
|
||||
const keys = await cache.keys();
|
||||
if (keys.length > maxEntries) {
|
||||
const toDelete = keys.slice(0, keys.length - maxEntries);
|
||||
await Promise.all(toDelete.map(k => cache.delete(k)));
|
||||
}
|
||||
} catch {} finally {
|
||||
_tileTrimRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Welche GET-API-Endpoints sollen gecacht werden?
|
||||
const _CACHEABLE_GET = [
|
||||
/^\/api\/dogs(\/\d+)?$/,
|
||||
|
|
@ -315,14 +335,18 @@ self.addEventListener('fetch', event => {
|
|||
return;
|
||||
}
|
||||
|
||||
// OSM-Kartenkacheln: eigener persistenter Cache
|
||||
// OSM-Kartenkacheln: eigener persistenter Cache (Cache-First mit LRU-Eviction)
|
||||
if (url.hostname.endsWith('tile.openstreetmap.org')) {
|
||||
event.respondWith(
|
||||
caches.open(CACHE_TILES).then(cache =>
|
||||
cache.match(event.request).then(cached => {
|
||||
if (cached) return cached;
|
||||
return fetch(event.request).then(response => {
|
||||
if (response.ok) cache.put(event.request, response.clone());
|
||||
if (response.ok) {
|
||||
cache.put(event.request, response.clone())
|
||||
.then(() => trimTileCache()) // im Hintergrund — blockiert respondWith nicht
|
||||
.catch(() => {});
|
||||
}
|
||||
return response;
|
||||
});
|
||||
})
|
||||
|
|
@ -435,6 +459,7 @@ self.addEventListener('message', event => {
|
|||
function fetchBatch() {
|
||||
if (queue.length === 0) {
|
||||
source?.postMessage({ type: 'CACHE_TILES_PROGRESS', done: total, total });
|
||||
trimTileCache(); // nach Bulk-Vorausladen einmal trimmen
|
||||
return;
|
||||
}
|
||||
const batch = queue.splice(0, 8);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue