#7 - Tentative fix
Added a 100ms pause every 100 indexed notes, to not block the main thread.
This commit is contained in:
21
src/main.ts
21
src/main.ts
@@ -1,4 +1,4 @@
|
|||||||
import { Plugin, SuggestModal, TAbstractFile, TFile } from 'obsidian'
|
import { Notice, Plugin, SuggestModal, TAbstractFile, TFile } from 'obsidian'
|
||||||
import MiniSearch from 'minisearch'
|
import MiniSearch from 'minisearch'
|
||||||
import removeMarkdown from 'remove-markdown'
|
import removeMarkdown from 'remove-markdown'
|
||||||
|
|
||||||
@@ -59,9 +59,18 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Index files that are already present
|
// Index files that are already present
|
||||||
|
const start = new Date().getTime()
|
||||||
const files = this.app.vault.getMarkdownFiles()
|
const files = this.app.vault.getMarkdownFiles()
|
||||||
for (const file of files) {
|
for (let i = 0; i < files.length; ++i) {
|
||||||
await this.addToIndex(file)
|
if (i % 100 === 0) await wait(100)
|
||||||
|
await this.addToIndex(files[i])
|
||||||
|
}
|
||||||
|
if (files.length > 0) {
|
||||||
|
new Notice(
|
||||||
|
`Omnisearch - Loaded ${files.length} notes in ${
|
||||||
|
new Date().getTime() - start
|
||||||
|
}ms`,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,3 +324,9 @@ function removeFrontMatter(text: string): string {
|
|||||||
// Regex to recognize YAML Front Matter (at beginning of file, 3 hyphens, than any charecter, including newlines, then 3 hyphens).
|
// Regex to recognize YAML Front Matter (at beginning of file, 3 hyphens, than any charecter, including newlines, then 3 hyphens).
|
||||||
return text.replace(regexYaml, '')
|
return text.replace(regexYaml, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wait(ms: number): Promise<void> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
setTimeout(resolve, ms)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user