Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array>} The search index.
*/
const fetchIndex = async () => {
await cleanupOld();
const key = `search2-${language}`;
let items;
if (language === 'local') {
Expand All @@ -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);
}
}

Expand Down