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)
|
public readonly searchEngine = new SearchEngine(this)
|
||||||
|
|
||||||
private ribbonButton?: HTMLElement
|
private ribbonButton?: HTMLElement
|
||||||
|
private refreshIndexCallback?: () => void
|
||||||
|
|
||||||
constructor(app: App, manifest: PluginManifest) {
|
constructor(app: App, manifest: PluginManifest) {
|
||||||
super(app, manifest)
|
super(app, manifest)
|
||||||
@@ -106,7 +107,6 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
this.app.vault.on('create', file => {
|
this.app.vault.on('create', file => {
|
||||||
if (this.notesIndexer.isFileIndexable(file.path)) {
|
if (this.notesIndexer.isFileIndexable(file.path)) {
|
||||||
logDebug('Indexing new file', file.path)
|
logDebug('Indexing new file', file.path)
|
||||||
// await cacheManager.addToLiveCache(file.path)
|
|
||||||
searchEngine.addFromPaths([file.path])
|
searchEngine.addFromPaths([file.path])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -121,8 +121,6 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
this.registerEvent(
|
this.registerEvent(
|
||||||
this.app.vault.on('modify', async file => {
|
this.app.vault.on('modify', async file => {
|
||||||
if (this.notesIndexer.isFileIndexable(file.path)) {
|
if (this.notesIndexer.isFileIndexable(file.path)) {
|
||||||
logDebug('Updating file', file.path)
|
|
||||||
await this.cacheManager.addToLiveCache(file.path)
|
|
||||||
this.notesIndexer.flagNoteForReindex(file)
|
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.executeFirstLaunchTasks()
|
||||||
await this.populateIndex()
|
await this.populateIndex()
|
||||||
|
|
||||||
@@ -165,6 +167,10 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
delete globalThis['omnisearch']
|
delete globalThis['omnisearch']
|
||||||
|
|
||||||
|
if (this.refreshIndexCallback) {
|
||||||
|
removeEventListener('blur', this.refreshIndexCallback)
|
||||||
|
}
|
||||||
|
|
||||||
// Clear cache when disabling Omnisearch
|
// Clear cache when disabling Omnisearch
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
await this.database.clearCache()
|
await this.database.clearCache()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
isFileFromDataloomPlugin,
|
isFileFromDataloomPlugin,
|
||||||
isFileImage,
|
isFileImage,
|
||||||
isFilePDF,
|
isFilePDF,
|
||||||
|
logDebug,
|
||||||
} from './tools/utils'
|
} from './tools/utils'
|
||||||
|
|
||||||
export class NotesIndexer {
|
export class NotesIndexer {
|
||||||
@@ -23,6 +24,11 @@ export class NotesIndexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async refreshIndex(): Promise<void> {
|
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)
|
const paths = [...this.notesToReindex].map(n => n.path)
|
||||||
if (paths.length) {
|
if (paths.length) {
|
||||||
this.plugin.searchEngine.removeFromPaths(paths)
|
this.plugin.searchEngine.removeFromPaths(paths)
|
||||||
|
|||||||
Reference in New Issue
Block a user