Slight indexing perf improvement

This commit is contained in:
Simon Cambier
2023-10-19 21:09:29 +02:00
parent 79d974764b
commit 51a9cc7d90

View File

@@ -1,4 +1,4 @@
import { Notice } from 'obsidian' import { Notice, TFile } from 'obsidian'
import { import {
type DocumentRef, type DocumentRef,
getTextExtractor, getTextExtractor,
@@ -32,8 +32,9 @@ import { settings } from './settings'
async function getAndMapIndexedDocument( async function getAndMapIndexedDocument(
path: string path: string
): Promise<IndexedDocument> { ): Promise<IndexedDocument> {
const file = app.vault.getFiles().find(f => f.path === path) const file = app.vault.getAbstractFileByPath(path)
if (!file) throw new Error(`Invalid file path: "${path}"`) if (!file) throw new Error(`Invalid file path: "${path}"`)
if (!(file instanceof TFile)) throw new Error(`Not a TFile: "${path}"`)
let content: string | null = null let content: string | null = null
const extractor = getTextExtractor() const extractor = getTextExtractor()