Logs & cleaning
This commit is contained in:
@@ -83,7 +83,6 @@ class CacheManager {
|
||||
public async addToLiveCache(path: string): Promise<void> {
|
||||
const doc = await getIndexedDocument(path)
|
||||
this.documents.set(path, doc)
|
||||
// console.log(path)
|
||||
}
|
||||
|
||||
public removeFromLiveCache(path: string): void {
|
||||
|
||||
@@ -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<IndexedDocument[]> {
|
||||
await Promise.all(input)
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a file into an IndexedDocument.
|
||||
* Will use the cache if possible.
|
||||
*/
|
||||
// async function fileToIndexedDocument(
|
||||
// file: TFile
|
||||
// ): Promise<IndexedDocument> {
|
||||
// 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(' ') : '',
|
||||
// }
|
||||
// }
|
||||
|
||||
17
src/main.ts
17
src/main.ts
@@ -116,6 +116,7 @@ async function populateIndex(): Promise<void> {
|
||||
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<void> {
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user