[hotfix] Fix cache clearing when switching folders (#4421)

* Update submodules

* Revert "Update submodules"

This reverts commit 1679ddeeea.

* 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.
This commit is contained in:
awsr
2025-11-25 06:58:45 -08:00
committed by GitHub
parent e64f8d7463
commit 691339773e
2 changed files with 12 additions and 6 deletions
+6 -3
View File
@@ -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();
+6 -3
View File
@@ -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);