From 691339773e36d692a0663cc511639146d319d4a0 Mon Sep 17 00:00:00 2001 From: awsr <43862868+awsr@users.noreply.github.com> Date: Tue, 25 Nov 2025 06:58:45 -0800 Subject: [PATCH] [hotfix] Fix cache clearing when switching folders (#4421) * Update submodules * Revert "Update submodules" This reverts commit 1679ddeeea3f7b9e2f6d00d0f90c8276e25fe995. * Fix cache clearing when switching folders This is more of a temporary hotfix since it will affect switching between gallery folders quickly and it'll kick off when viewing small folders. --- javascript/gallery.js | 9 ++++++--- javascript/indexdb.js | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/javascript/gallery.js b/javascript/gallery.js index e8589c71f..d3d8825dc 100644 --- a/javascript/gallery.js +++ b/javascript/gallery.js @@ -7,6 +7,7 @@ let outstanding = 0; let lastSort = 0; let lastSortName = 'None'; let idbIsCleaning = false; +let activeGalleryFolder = ''; const galleryHashes = new Set(); // Store separator states for the session const separatorStates = new Map(); @@ -592,10 +593,10 @@ async function thumbCacheCleanup() { } const removeOverlayFunc = showCleaningMsg(); - idbClean(galleryHashes) - .then((delcount) => { + idbClean(galleryHashes, activeGalleryFolder) + .then((delcount, folder) => { const t1 = performance.now(); - log(`Thumbnail DB cleanup: kept=${galleryHashes.size} deleted=${delcount} time=${Math.floor(t1 - t0)}ms`); + log(`Thumbnail DB cleanup: folder=${folder} kept=${galleryHashes.size} deleted=${delcount} time=${Math.floor(t1 - t0)}ms`); }) .catch((err) => { error('Thumbnail DB cleanup: Cleanup failed.', err.message); @@ -632,6 +633,7 @@ async function fetchFilesHT(evt) { el.files.appendChild(fragment); const t1 = performance.now(); + activeGalleryFolder = evt.target.name; log(`gallery: folder=${evt.target.name} num=${numFiles} time=${Math.floor(t1 - t0)}ms`); updateStatusWithSort(`Folder: ${evt.target.name} | ${numFiles.toLocaleString()} images | ${Math.floor(t1 - t0).toLocaleString()}ms`); addSeparators(); @@ -686,6 +688,7 @@ async function fetchFilesWS(evt) { // fetch file-by-file list over websockets ws.onclose = (event) => { el.files.appendChild(fragment); // gallerySort(); + activeGalleryFolder = evt.target.name; log(`gallery: folder=${evt.target.name} num=${numFiles} time=${Math.floor(t1 - t0)}ms`); updateStatusWithSort(`Folder: ${evt.target.name} | ${numFiles.toLocaleString()} images | ${Math.floor(t1 - t0).toLocaleString()}ms`); addSeparators(); diff --git a/javascript/indexdb.js b/javascript/indexdb.js index 5a4186fcf..ee84cde12 100644 --- a/javascript/indexdb.js +++ b/javascript/indexdb.js @@ -99,11 +99,14 @@ async function idbCount() { }); } -async function idbClean(keepSet) { +async function idbClean(keepSet, folder = null) { if (!db) return null; if (!(keepSet instanceof Set)) { throw new TypeError('IndexedDB cleaning function must be given a Set() of hashes to keep'); } + if (folder === null) { + throw new Error('IndexedDB cleaning function must be told the current active folder'); + } return new Promise((resolve, reject) => { let counter = 0; const request = db @@ -113,13 +116,13 @@ async function idbClean(keepSet) { request.onsuccess = (evt) => { const cursor = evt.target.result; if (cursor) { - if (!keepSet.has(cursor.key)) { + if (folder === cursor.value.folder && !keepSet.has(cursor.key)) { cursor.delete(); counter++; } cursor.continue(); } else { - resolve(counter); + resolve(counter, folder); } }; request.onerror = (evt) => reject(evt);