Removed useless cache writing

This commit is contained in:
Simon Cambier
2022-12-07 18:19:59 +01:00
parent b749f22510
commit 18e7c011bc
3 changed files with 5 additions and 16 deletions

View File

@@ -56,7 +56,7 @@ export default class OmnisearchPlugin extends Plugin {
this.app.vault.on('create', async file => {
if (isFileIndexable(file.path)) {
await cacheManager.addToLiveCache(file.path)
searchEngine.addFromPaths([file.path], false)
searchEngine.addFromPaths([file.path])
}
})
)
@@ -80,7 +80,7 @@ export default class OmnisearchPlugin extends Plugin {
cacheManager.removeFromLiveCache(oldPath)
cacheManager.addToLiveCache(file.path)
searchEngine.removeFromPaths([oldPath])
await searchEngine.addFromPaths([file.path], false)
await searchEngine.addFromPaths([file.path])
}
})
)
@@ -157,10 +157,7 @@ async function populateIndex(): Promise<void> {
indexingStep.set(IndexingStepType.IndexingFiles)
searchEngine.removeFromPaths(diff.toRemove.map(o => o.path))
await searchEngine.addFromPaths(
diff.toAdd.map(o => o.path),
true
)
await searchEngine.addFromPaths(diff.toAdd.map(o => o.path))
if (diff.toRemove.length || diff.toAdd.length) {
indexingStep.set(IndexingStepType.WritingCache)

View File

@@ -45,7 +45,7 @@ export async function refreshIndex(): Promise<void> {
const paths = [...notesToReindex].map(n => n.path)
if (paths.length) {
searchEngine.removeFromPaths(paths)
searchEngine.addFromPaths(paths, false)
searchEngine.addFromPaths(paths)
notesToReindex.clear()
// console.log(`Omnisearch - Reindexed ${paths.length} file(s)`)
}

View File

@@ -101,10 +101,7 @@ export class Omnisearch {
* Add notes/PDFs/images to the search index
* @param paths
*/
public async addFromPaths(
paths: string[],
mustWriteToCache: boolean
): Promise<void> {
public async addFromPaths(paths: string[]): Promise<void> {
let documents = await Promise.all(
paths.map(async path => await cacheManager.getDocument(path))
)
@@ -127,10 +124,6 @@ export class Omnisearch {
// Add docs to minisearch
await this.minisearch.addAllAsync(docs)
// Save the index
if (mustWriteToCache) {
await this.writeToCache()
}
}
}
@@ -305,7 +298,6 @@ export class Omnisearch {
.filter(s => s.value.startsWith('#'))
.map(s => s.value)
// TODO: this already called in search(), pass each document in its SearchResult instead?
const documents = await Promise.all(
results.map(async result => await cacheManager.getDocument(result.id))
)