fix: using a debounced function to clear the cache when triggered by a text field

This commit is contained in:
Simon Cambier
2024-06-29 16:14:02 +02:00
parent da161b8ffe
commit 1d64ca52cc

View File

@@ -12,6 +12,7 @@ import { writable } from 'svelte/store'
import { K_DISABLE_OMNISEARCH } from './globals'
import type OmnisearchPlugin from './main'
import { enablePrintDebug } from './tools/utils'
import { debounce } from 'lodash-es'
interface WeightingSettings {
weightBasename: number
@@ -98,6 +99,11 @@ export class SettingsTab extends PluginSettingTab {
const { containerEl } = this
const database = this.plugin.database
const textExtractor = this.plugin.getTextExtractor()
const clearCacheDebounced = debounce(async () => {
await database.clearCache()
}, 1000)
containerEl.empty()
if (this.app.loadLocalStorage(K_DISABLE_OMNISEARCH) == '1') {
@@ -197,7 +203,7 @@ export class SettingsTab extends PluginSettingTab {
.addOptions({ yes: 'Yes', no: 'No', default: 'Obsidian setting' })
.setValue(settings.unsupportedFilesIndexing)
.onChange(async v => {
await database.clearCache()
await clearCacheDebounced()
;(settings.unsupportedFilesIndexing as any) = v
await saveSettings(this.plugin)
})