Don't needlessly refresh the live cache

This commit is contained in:
Simon Cambier
2024-06-07 12:30:00 +02:00
parent 0d6ed3eb61
commit 2f6e25ce47
2 changed files with 15 additions and 3 deletions

View File

@@ -42,6 +42,7 @@ export default class OmnisearchPlugin extends Plugin {
public readonly searchEngine = new SearchEngine(this)
private ribbonButton?: HTMLElement
private refreshIndexCallback?: () => void
constructor(app: App, manifest: PluginManifest) {
super(app, manifest)
@@ -106,7 +107,6 @@ export default class OmnisearchPlugin extends Plugin {
this.app.vault.on('create', file => {
if (this.notesIndexer.isFileIndexable(file.path)) {
logDebug('Indexing new file', file.path)
// await cacheManager.addToLiveCache(file.path)
searchEngine.addFromPaths([file.path])
}
})
@@ -121,8 +121,6 @@ export default class OmnisearchPlugin extends Plugin {
this.registerEvent(
this.app.vault.on('modify', async file => {
if (this.notesIndexer.isFileIndexable(file.path)) {
logDebug('Updating file', file.path)
await this.cacheManager.addToLiveCache(file.path)
this.notesIndexer.flagNoteForReindex(file)
}
})
@@ -139,6 +137,10 @@ export default class OmnisearchPlugin extends Plugin {
})
)
this.refreshIndexCallback = this.notesIndexer.refreshIndex.bind(this.notesIndexer)
addEventListener('blur', this.refreshIndexCallback)
removeEventListener
await this.executeFirstLaunchTasks()
await this.populateIndex()
@@ -165,6 +167,10 @@ export default class OmnisearchPlugin extends Plugin {
// @ts-ignore
delete globalThis['omnisearch']
if (this.refreshIndexCallback) {
removeEventListener('blur', this.refreshIndexCallback)
}
// Clear cache when disabling Omnisearch
if (process.env.NODE_ENV === 'production') {
await this.database.clearCache()