Remove key hashing and explicitly clear the cache after printing characters

e1d6a47048e0d53921214607387f2687d2fb805f

Joe <joenunezb@gmail.com>

2 files changed, +11 -18Ignore whitespace
public/script.js+2 -0
@@ -268,6 +268,7 @@ import { initServerHistory } from './scripts/server-history.js';
268268import { initSettingsSearch } from './scripts/setting-search.js';
269269import { initBulkEdit } from './scripts/bulk-edit.js';
270270import { deriveTemplatesFromChatTemplate } from './scripts/chat-templates.js';
271+import { clearFuzzySearchCaches } from './scripts/power-user.js';
271272
272273//exporting functions and vars for mods
273274export {
@@ -1515,6 +1516,7 @@ export async function printCharacters(fullRefresh = false) {
15151516 });
15161517
15171518 favsToHotswap();
1519+ clearFuzzySearchCaches();
15181520}
15191521
15201522/** Checks the state of the current search, and adds/removes the search sorting option accordingly */
public/scripts/power-user.js+9 -18
@@ -329,11 +329,11 @@ let browser_has_focus = true;
329329const debug_functions = [];
330330
331331const fuzzySearchCaches = {
332332 characters: { keyHash: null, resultMap: new Map() },
333333 worldInfo: { keyHash: null, resultMap: new Map() },
334334 personas: { keyHash: null, resultMap: new Map() },
335335 tags: { keyHash: null, resultMap: new Map() },
336336 groups: { keyHash: null, resultMap: new Map() },
337337};
338338
339339const fuzzySearchCategories = {
@@ -1864,22 +1864,14 @@ function hashFuseKeys(keys) {
18641864 * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score
18651865 */
18661866function performFuzzySearch(type, data, keys, searchValue) {
1867- const currentKeyHash = hashFuseKeys(keys);
18681867 const cache = fuzzySearchCaches[type];
18691868
18701869 // Check cache for existing results
18711870 if (cache.keyHash === currentKeyHash && cache.resultMap.has(searchValue)) {
1872- // console.debug(`Using cached ${type} fuzzy search results for ${searchValue}`);
18731871 return cache.resultMap.get(searchValue);
18741872 }
18751873
1876- // Clear cache if keys changed
1874+ // @ts-ignore
1877- if (cache.keyHash !== currentKeyHash) {
1878- // console.debug(`${type} Fuse keys changed, clearing cache`);
1879- cache.keyHash = currentKeyHash;
1880- cache.resultMap.clear();
1881- }
1882-
18831875 const fuse = new Fuse(data, {
18841876 keys: keys,
18851877 includeScore: true,
@@ -1890,19 +1882,18 @@ function performFuzzySearch(type, data, keys, searchValue) {
18901882
18911883 const results = fuse.search(searchValue);
18921884 cache.resultMap.set(searchValue, results);
1893-
1894- // console.debug(`${type} fuzzy search results for ${searchValue}`, results);
18951885 return results;
18961886}
18971887
1888+
18981889/**
18991890 * Clears all fuzzy search caches
19001891 */
19011892export function clearFuzzySearchCaches() {
19021893 for (const cache of Object.values(fuzzySearchCaches)) {
1903- cache.keyHash = null;
19041894 cache.resultMap.clear();
19051895 }
1896+ console.log('Fuzzy search caches cleared');
19061897}
19071898
19081899/**