From 9ceed935ceca820f670c2edbaa7c5a6a7f151e8c Mon Sep 17 00:00:00 2001 From: awsr <43862868+awsr@users.noreply.github.com> Date: Fri, 28 Nov 2025 13:21:24 -0800 Subject: [PATCH] Naming changes and additional check --- javascript/gallery.js | 19 +++++++++++-------- javascript/indexdb.js | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/javascript/gallery.js b/javascript/gallery.js index d20e82284..d69b09e3c 100644 --- a/javascript/gallery.js +++ b/javascript/gallery.js @@ -568,19 +568,19 @@ async function gallerySort(btn) { /** * Function for updating the cleaning overlay message - * @callback updateMsgCallback + * @callback UpdateMsgCallback * @param {number} progressPercent - Value for completion progress percentage * @returns {void} */ /** * Function for removing the cleaning overlay - * @callback clearMsgCallback + * @callback ClearMsgCallback * @returns {void} */ /** * Generate and display the overlay to announce cleanup is in progress. - * @returns {[updateMsgCallback, clearMsgCallback]} + * @returns {[UpdateMsgCallback, ClearMsgCallback]} */ function showCleaningMsg() { const parent = el.folders.parentElement; @@ -608,14 +608,17 @@ function showCleaningMsg() { } /** - * IndexedDB thumbnail cache cleanup function + * Handles calling the cleanup function for the thumbnail cache * @param {string} folder - Folder to clean * @param {number} imgCount - Expected number of images in gallery */ async function thumbCacheCleanup(folder, imgCount) { if (idbIsCleaning) return; - await awaitForIDB(); try { + if (typeof folder !== 'string' || typeof imgCount !== 'number') { + throw new Error('Function called with invalid arguments'); + } + await awaitForIDB(); await awaitForGallery(folder, imgCount); } catch (err) { log('Thumbnail DB cleanup:', err.message); @@ -634,8 +637,8 @@ async function thumbCacheCleanup(folder, imgCount) { if (activeGalleryFolder !== folder || idbIsCleaning) return; // Second check for other thread activity idbIsCleaning = true; - const [updateCleaningMsg, removeOverlayFunc] = showCleaningMsg(); - idbFolderCleanup(staticGalleryHashes, folder, updateCleaningMsg) + const [cb_updateMsg, cb_clearMsg] = showCleaningMsg(); + idbFolderCleanup(staticGalleryHashes, folder, cb_updateMsg) .then((delcount) => { const t1 = performance.now(); log(`Thumbnail DB cleanup: folder=${folder} kept=${staticGalleryHashes.size} deleted=${delcount} time=${Math.floor(t1 - t0)}ms`); @@ -644,7 +647,7 @@ async function thumbCacheCleanup(folder, imgCount) { error('Thumbnail DB cleanup: Cleanup failed.', err.message); }) .finally(() => { - removeOverlayFunc(); + cb_clearMsg(); idbIsCleaning = false; }); } diff --git a/javascript/indexdb.js b/javascript/indexdb.js index e823b88dd..cba86e8eb 100644 --- a/javascript/indexdb.js +++ b/javascript/indexdb.js @@ -129,7 +129,7 @@ async function idbCount(folder = null) { * @global * @param {Set} keepSet - Set containing the hashes of the current files in the folder. * @param {string} folder - Folder name/path. - * @param {updateMsgCallback} msgCallback - Callback for updating the overlay message progress. + * @param {UpdateMsgCallback} msgCallback - Callback for updating the overlay message progress. */ async function idbFolderCleanup(keepSet, folder, msgCallback) { if (!db) return null;