From 8138855cff02c93e20b905a1e00705b6c194c215 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sun, 2 Oct 2022 22:23:13 +0200 Subject: [PATCH] Disabled PDF indexing due to Electron crash --- src/main.ts | 2 +- src/search.ts | 19 +++++++++++++------ src/settings.ts | 34 +++++++++++++++++----------------- src/utils.ts | 6 +++++- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/main.ts b/src/main.ts index 0a8230e..013bdc1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -82,7 +82,7 @@ export default class OmnisearchPlugin extends Plugin { await initGlobalSearchIndex() }) - showWelcomeNotice(this) + // showWelcomeNotice(this) } onunload(): void {} diff --git a/src/search.ts b/src/search.ts index c89a46a..ce3251d 100644 --- a/src/search.ts +++ b/src/search.ts @@ -9,6 +9,7 @@ import { SPACE_OR_PUNCTUATION, } from './globals' import { + canIndexPDFs, isFilePlaintext, removeDiacritics, stringsToRegex, @@ -100,14 +101,18 @@ export async function initGlobalSearchIndex(): Promise { // This is basically the same behavior as MiniSearch's `addAllAsync()`. // We index markdown and plaintext files by batches of 10 - const promises: Promise[] = [] + let promises: Promise[] = [] for (let i = 0; i < files.length; ++i) { - if (i % 10 === 0) await wait(0) const file = files[i] if (getNoteFromCache(file.path)) { removeFromIndex(file.path) } promises.push(addToIndex(file)) + if (i % 10 === 0) { + await wait(1) + await Promise.all(promises) + promises = [] + } } await Promise.all(promises) @@ -130,20 +135,22 @@ export async function initGlobalSearchIndex(): Promise { } async function indexPDFs() { - if (settings.indexPDFs) { + if (canIndexPDFs()) { const start = new Date().getTime() console.warn( "Omnisearch - Warnings on 'pdf.worker.min' are due to some issues while reading PDFs file and can usually be ignored." ) const files = app.vault.getFiles().filter(f => f.path.endsWith('.pdf')) - const promises: Promise[] = [] + let promises: Promise[] = [] for (const [i, file] of files.entries()) { if (getNoteFromCache(file.path)) { removeFromIndex(file.path) } promises.push(addToIndex(file)) - if (i % 10 == 0) { - promises.push(wait(10)) + if (i % 10 === 0) { + await wait(1) + await Promise.all(promises) + promises = [] } } await Promise.all(promises) diff --git a/src/settings.ts b/src/settings.ts index 5681849..f8ce735 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -106,23 +106,23 @@ export class SettingsTab extends PluginSettingTab { }) }) - // Index PDFs - const indexPDFsDesc = new DocumentFragment() - indexPDFsDesc.createSpan({}, span => { - span.innerHTML = `Omnisearch will index your PDFs, and return them in search results. - This feature is currently a work-in-progress, please report slowdowns or issues that you might experience.
- PDFs being quite slow to index, it is strongly recommended to also enable "Store index in file".
- Needs a restart to fully take effect.` - }) - new Setting(containerEl) - .setName('BETA - Index PDFs') - .setDesc(indexPDFsDesc) - .addToggle(toggle => - toggle.setValue(settings.indexPDFs).onChange(async v => { - settings.indexPDFs = v - await saveSettings(this.plugin) - }) - ) + // // Index PDFs + // const indexPDFsDesc = new DocumentFragment() + // indexPDFsDesc.createSpan({}, span => { + // span.innerHTML = `Omnisearch will index your PDFs, and return them in search results. + // This feature is currently a work-in-progress, please report slowdowns or issues that you might experience.
+ // PDFs being quite slow to index, it is strongly recommended to also enable "Store index in file".
+ // Needs a restart to fully take effect.` + // }) + // new Setting(containerEl) + // .setName('BETA - Index PDFs') + // .setDesc(indexPDFsDesc) + // .addToggle(toggle => + // toggle.setValue(settings.indexPDFs).onChange(async v => { + // settings.indexPDFs = v + // await saveSettings(this.plugin) + // }) + // ) // Store index const serializedIndexDesc = new DocumentFragment() diff --git a/src/utils.ts b/src/utils.ts index 89889b7..4a8fcf4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -172,8 +172,12 @@ export function getCtrlKeyLabel(): 'ctrl' | '⌘' { return Platform.isMacOS ? '⌘' : 'ctrl' } +export function canIndexPDFs(): boolean { + return false +} + export function isFileIndexable(path: string): boolean { - return (settings.indexPDFs && path.endsWith('.pdf')) || isFilePlaintext(path) + return (canIndexPDFs() && path.endsWith('.pdf')) || isFilePlaintext(path) } export function isFilePlaintext(path: string): boolean {