From e8d0efbd5b11e82703ed180f0d1f9b3238a35e70 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sun, 27 Nov 2022 16:36:06 +0100 Subject: [PATCH] Logs & cleaning --- src/cache-manager.ts | 1 - src/file-loader.ts | 60 +------------------------------------------- src/main.ts | 17 ++++++++----- 3 files changed, 12 insertions(+), 66 deletions(-) diff --git a/src/cache-manager.ts b/src/cache-manager.ts index 1065165..64e4834 100644 --- a/src/cache-manager.ts +++ b/src/cache-manager.ts @@ -83,7 +83,6 @@ class CacheManager { public async addToLiveCache(path: string): Promise { const doc = await getIndexedDocument(path) this.documents.set(path, doc) - // console.log(path) } public removeFromLiveCache(path: string): void { diff --git a/src/file-loader.ts b/src/file-loader.ts index 9c4c2ea..662e38d 100644 --- a/src/file-loader.ts +++ b/src/file-loader.ts @@ -10,7 +10,7 @@ import { import type { TFile } from 'obsidian' import type { IndexedDocument } from './globals' import { getImageText, getPdfText } from 'obsidian-text-extract' -import { cacheManager } from "./cache-manager"; +import { cacheManager } from './cache-manager' /** * Return all plaintext files as IndexedDocuments @@ -57,61 +57,3 @@ async function getBinaryFiles(files: TFile[]): Promise { await Promise.all(input) return data } - -/** - * Convert a file into an IndexedDocument. - * Will use the cache if possible. - */ -// async function fileToIndexedDocument( -// file: TFile -// ): Promise { -// let content: string -// if (isFilePlaintext(file.path)) { -// content = await app.vault.cachedRead(file) -// } else if (isFilePDF(file.path)) { -// content = await getPdfText(file) -// } else if (isFileImage(file.path)) { -// content = await getImageText(file) -// } else { -// throw new Error('Invalid file: ' + file.path) -// } -// -// content = removeDiacritics(content) -// const metadata = app.metadataCache.getFileCache(file) -// -// // Look for links that lead to non-existing files, -// // and add them to the index. -// if (metadata) { -// // FIXME: https://github.com/scambier/obsidian-omnisearch/issues/129 -// const nonExisting = getNonExistingNotes(file, metadata) -// for (const name of nonExisting.filter( -// o => !cacheManager.getLiveDocument(o) -// )) { -// NotesIndex.addNonExistingToIndex(name, file.path) -// } -// -// // EXCALIDRAW -// // Remove the json code -// if (metadata.frontmatter?.['excalidraw-plugin']) { -// const comments = -// metadata.sections?.filter(s => s.type === 'comment') ?? [] -// for (const { start, end } of comments.map(c => c.position)) { -// content = -// content.substring(0, start.offset - 1) + content.substring(end.offset) -// } -// } -// } -// -// return { -// basename: removeDiacritics(file.basename), -// content, -// path: file.path, -// mtime: file.stat.mtime, -// -// tags: getTagsFromMetadata(metadata), -// aliases: getAliasesFromMetadata(metadata).join(''), -// headings1: metadata ? extractHeadingsFromCache(metadata, 1).join(' ') : '', -// headings2: metadata ? extractHeadingsFromCache(metadata, 2).join(' ') : '', -// headings3: metadata ? extractHeadingsFromCache(metadata, 3).join(' ') : '', -// } -// } diff --git a/src/main.ts b/src/main.ts index c62e756..b74f0db 100644 --- a/src/main.ts +++ b/src/main.ts @@ -116,6 +116,7 @@ async function populateIndex(): Promise { console.time('Omnisearch - Indexing total time') indexingStep.set(IndexingStepType.ReadingFiles) const files = app.vault.getFiles().filter(f => isFileIndexable(f.path)) + console.log(`Omnisearch - ${files.length} files total`) // Map documents in the background // Promise.all(files.map(f => cacheManager.addToLiveCache(f.path))) @@ -130,12 +131,16 @@ async function populateIndex(): Promise { files.map(f => ({ path: f.path, mtime: f.stat.mtime })) ) - console.log( - 'Omnisearch - Total number of files to add/update: ' + diff.toAdd.length - ) - console.log( - 'Omnisearch - Total number of files to remove: ' + diff.toRemove.length - ) + if (diff.toAdd.length) { + console.log( + 'Omnisearch - Total number of files to add/update: ' + diff.toAdd.length + ) + } + if (diff.toRemove.length) { + console.log( + 'Omnisearch - Total number of files to remove: ' + diff.toRemove.length + ) + } if (diff.toAdd.length >= 500) { new Notice(