diff --git a/.eslintrc.json b/.eslintrc.json index a957e1335..b5ae04c04 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -117,7 +117,7 @@ "idbDel": "readonly", "idbAdd": "readonly", "idbCount": "readonly", - "idbClean": "readonly", + "idbFolderCleanup": "readonly", "initChangelog": "readonly", "sendNotification": "readonly", "monitorConnection": "readonly" diff --git a/javascript/gallery.js b/javascript/gallery.js index 028f622c1..ca1e524d5 100644 --- a/javascript/gallery.js +++ b/javascript/gallery.js @@ -635,7 +635,7 @@ async function thumbCacheCleanup(folder, imgCount) { idbIsCleaning = true; const [updateCleaningMsg, removeOverlayFunc] = showCleaningMsg(); - idbClean(staticGalleryHashes, folder, updateCleaningMsg) + idbFolderCleanup(staticGalleryHashes, folder, updateCleaningMsg) .then((delcount) => { const t1 = performance.now(); log(`Thumbnail DB cleanup: folder=${folder} kept=${staticGalleryHashes.size} deleted=${delcount} time=${Math.floor(t1 - t0)}ms`); diff --git a/javascript/indexdb.js b/javascript/indexdb.js index 490eb46f6..0adb76b57 100644 --- a/javascript/indexdb.js +++ b/javascript/indexdb.js @@ -123,16 +123,15 @@ async function idbCount(folder = null) { * @param {string} folder - Folder name/path * @param {updateMsgCallback} msgCallback - Callback for updating progress display */ -async function idbClean(keepSet, folder, msgCallback) { +async function idbFolderCleanup(keepSet, folder, msgCallback) { if (!db) return null; if (!(keepSet instanceof Set)) { - throw new TypeError('IndexedDB cleaning function must be given a Set() of hashes to keep'); + throw new TypeError('IndexedDB cleaning function must be given a Set() of the current gallery hashes'); } - if (!folder) { + if (!folder || typeof folder !== 'string') { throw new Error('IndexedDB cleaning function must be told the current active folder'); } - const folderCached = new Set(await idbGetAllKeys('folder', folder)); - const removals = folderCached.difference(keepSet); + const removals = (new Set(await idbGetAllKeys('folder', folder))).difference(keepSet); const totalRemovals = removals.size; let counter = 0; return new Promise((resolve, reject) => {