Skip to content

Commit 6b74785

Browse files
committed
Search: Clear any old caches to free up quota; Change quota exceeded console message level to info
1 parent 658fafe commit 6b74785

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

js/search.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,26 @@ const initPHPSearch = async (language) => {
3535
return data;
3636
};
3737

38+
const cleanupOld = async() => {
39+
// Previously used cache key
40+
const key = `search-${language}`;
41+
const oldCache = window.localStorage.getItem(key);
42+
if (!oldCache) {
43+
return;
44+
}
45+
46+
// Clear is used to clear all cached languages at the same time
47+
// This reduces the chances of hitting quota
48+
window.localStorage.clear();
49+
}
50+
3851
/**
3952
* Fetch the search index.
4053
*
4154
* @returns {Promise<Array>} The search index.
4255
*/
4356
const fetchIndex = async () => {
57+
await cleanupOld();
4458
const key = `search2-${language}`;
4559
let items;
4660
if (language === 'local') {
@@ -60,7 +74,7 @@ const initPHPSearch = async (language) => {
6074
} catch (e) {
6175
// Local storage might be full, or other error.
6276
// Just continue without caching.
63-
console.error("Failed to cache search index", e);
77+
console.info("Failed to cache search index", e);
6478
}
6579
}
6680

0 commit comments

Comments
 (0)