From 6b7478521d6d7eca952a652ad41e25893de247c5 Mon Sep 17 00:00:00 2001 From: AllenJB Date: Wed, 5 Nov 2025 20:55:15 +0000 Subject: [PATCH] Search: Clear any old caches to free up quota; Change quota exceeded console message level to info --- js/search.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/js/search.js b/js/search.js index 807360ca99..4bb837410f 100644 --- a/js/search.js +++ b/js/search.js @@ -35,12 +35,26 @@ const initPHPSearch = async (language) => { return data; }; + const cleanupOld = async() => { + // Previously used cache key + const key = `search-${language}`; + const oldCache = window.localStorage.getItem(key); + if (!oldCache) { + return; + } + + // Clear is used to clear all cached languages at the same time + // This reduces the chances of hitting quota + window.localStorage.clear(); + } + /** * Fetch the search index. * * @returns {Promise} The search index. */ const fetchIndex = async () => { + await cleanupOld(); const key = `search2-${language}`; let items; if (language === 'local') { @@ -60,7 +74,7 @@ const initPHPSearch = async (language) => { } catch (e) { // Local storage might be full, or other error. // Just continue without caching. - console.error("Failed to cache search index", e); + console.info("Failed to cache search index", e); } }