Don't needlessly refresh the live cache
This commit is contained in:
12
src/main.ts
12
src/main.ts
@@ -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()
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
isFileFromDataloomPlugin,
|
||||
isFileImage,
|
||||
isFilePDF,
|
||||
logDebug,
|
||||
} from './tools/utils'
|
||||
|
||||
export class NotesIndexer {
|
||||
@@ -23,6 +24,11 @@ export class NotesIndexer {
|
||||
}
|
||||
|
||||
public async refreshIndex(): Promise<void> {
|
||||
for (const file of this.notesToReindex) {
|
||||
logDebug('Updating file', file.path)
|
||||
await this.plugin.cacheManager.addToLiveCache(file.path)
|
||||
}
|
||||
|
||||
const paths = [...this.notesToReindex].map(n => n.path)
|
||||
if (paths.length) {
|
||||
this.plugin.searchEngine.removeFromPaths(paths)
|
||||
|
||||
Reference in New Issue
Block a user