Logs & cleaning
This commit is contained in:
@@ -83,7 +83,6 @@ class CacheManager {
|
|||||||
public async addToLiveCache(path: string): Promise<void> {
|
public async addToLiveCache(path: string): Promise<void> {
|
||||||
const doc = await getIndexedDocument(path)
|
const doc = await getIndexedDocument(path)
|
||||||
this.documents.set(path, doc)
|
this.documents.set(path, doc)
|
||||||
// console.log(path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeFromLiveCache(path: string): void {
|
public removeFromLiveCache(path: string): void {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
import type { TFile } from 'obsidian'
|
import type { TFile } from 'obsidian'
|
||||||
import type { IndexedDocument } from './globals'
|
import type { IndexedDocument } from './globals'
|
||||||
import { getImageText, getPdfText } from 'obsidian-text-extract'
|
import { getImageText, getPdfText } from 'obsidian-text-extract'
|
||||||
import { cacheManager } from "./cache-manager";
|
import { cacheManager } from './cache-manager'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all plaintext files as IndexedDocuments
|
* Return all plaintext files as IndexedDocuments
|
||||||
@@ -57,61 +57,3 @@ async function getBinaryFiles(files: TFile[]): Promise<IndexedDocument[]> {
|
|||||||
await Promise.all(input)
|
await Promise.all(input)
|
||||||
return data
|
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')
|
console.time('Omnisearch - Indexing total time')
|
||||||
indexingStep.set(IndexingStepType.ReadingFiles)
|
indexingStep.set(IndexingStepType.ReadingFiles)
|
||||||
const files = app.vault.getFiles().filter(f => isFileIndexable(f.path))
|
const files = app.vault.getFiles().filter(f => isFileIndexable(f.path))
|
||||||
|
console.log(`Omnisearch - ${files.length} files total`)
|
||||||
|
|
||||||
// Map documents in the background
|
// Map documents in the background
|
||||||
// Promise.all(files.map(f => cacheManager.addToLiveCache(f.path)))
|
// 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 }))
|
files.map(f => ({ path: f.path, mtime: f.stat.mtime }))
|
||||||
)
|
)
|
||||||
|
|
||||||
console.log(
|
if (diff.toAdd.length) {
|
||||||
'Omnisearch - Total number of files to add/update: ' + diff.toAdd.length
|
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.toRemove.length) {
|
||||||
|
console.log(
|
||||||
|
'Omnisearch - Total number of files to remove: ' + diff.toRemove.length
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (diff.toAdd.length >= 500) {
|
if (diff.toAdd.length >= 500) {
|
||||||
new Notice(
|
new Notice(
|
||||||
|
|||||||
Reference in New Issue
Block a user