Disabled PDF indexing due to Electron crash

This commit is contained in:
Simon Cambier
2022-10-02 22:23:13 +02:00
parent a4920c223e
commit 8138855cff
4 changed files with 36 additions and 25 deletions

View File

@@ -82,7 +82,7 @@ export default class OmnisearchPlugin extends Plugin {
await initGlobalSearchIndex() await initGlobalSearchIndex()
}) })
showWelcomeNotice(this) // showWelcomeNotice(this)
} }
onunload(): void {} onunload(): void {}

View File

@@ -9,6 +9,7 @@ import {
SPACE_OR_PUNCTUATION, SPACE_OR_PUNCTUATION,
} from './globals' } from './globals'
import { import {
canIndexPDFs,
isFilePlaintext, isFilePlaintext,
removeDiacritics, removeDiacritics,
stringsToRegex, stringsToRegex,
@@ -100,14 +101,18 @@ export async function initGlobalSearchIndex(): Promise<void> {
// This is basically the same behavior as MiniSearch's `addAllAsync()`. // This is basically the same behavior as MiniSearch's `addAllAsync()`.
// We index markdown and plaintext files by batches of 10 // We index markdown and plaintext files by batches of 10
const promises: Promise<void>[] = [] let promises: Promise<void>[] = []
for (let i = 0; i < files.length; ++i) { for (let i = 0; i < files.length; ++i) {
if (i % 10 === 0) await wait(0)
const file = files[i] const file = files[i]
if (getNoteFromCache(file.path)) { if (getNoteFromCache(file.path)) {
removeFromIndex(file.path) removeFromIndex(file.path)
} }
promises.push(addToIndex(file)) promises.push(addToIndex(file))
if (i % 10 === 0) {
await wait(1)
await Promise.all(promises)
promises = []
}
} }
await Promise.all(promises) await Promise.all(promises)
@@ -130,20 +135,22 @@ export async function initGlobalSearchIndex(): Promise<void> {
} }
async function indexPDFs() { async function indexPDFs() {
if (settings.indexPDFs) { if (canIndexPDFs()) {
const start = new Date().getTime() const start = new Date().getTime()
console.warn( console.warn(
"Omnisearch - Warnings on 'pdf.worker.min' are due to some issues while reading PDFs file and can usually be ignored." "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 files = app.vault.getFiles().filter(f => f.path.endsWith('.pdf'))
const promises: Promise<void>[] = [] let promises: Promise<void>[] = []
for (const [i, file] of files.entries()) { for (const [i, file] of files.entries()) {
if (getNoteFromCache(file.path)) { if (getNoteFromCache(file.path)) {
removeFromIndex(file.path) removeFromIndex(file.path)
} }
promises.push(addToIndex(file)) promises.push(addToIndex(file))
if (i % 10 == 0) { if (i % 10 === 0) {
promises.push(wait(10)) await wait(1)
await Promise.all(promises)
promises = []
} }
} }
await Promise.all(promises) await Promise.all(promises)

View File

@@ -106,23 +106,23 @@ export class SettingsTab extends PluginSettingTab {
}) })
}) })
// Index PDFs // // Index PDFs
const indexPDFsDesc = new DocumentFragment() // const indexPDFsDesc = new DocumentFragment()
indexPDFsDesc.createSpan({}, span => { // indexPDFsDesc.createSpan({}, span => {
span.innerHTML = `Omnisearch will index your PDFs, and return them in search results. // 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.<br> // This feature is currently a work-in-progress, please report slowdowns or issues that you might experience.<br>
PDFs being quite slow to index, <strong style="color: var(--text-accent)">it is strongly recommended to also enable "Store index in file"</strong>.<br> // PDFs being quite slow to index, <strong style="color: var(--text-accent)">it is strongly recommended to also enable "Store index in file"</strong>.<br>
<strong>Needs a restart to fully take effect.</strong>` // <strong>Needs a restart to fully take effect.</strong>`
}) // })
new Setting(containerEl) // new Setting(containerEl)
.setName('BETA - Index PDFs') // .setName('BETA - Index PDFs')
.setDesc(indexPDFsDesc) // .setDesc(indexPDFsDesc)
.addToggle(toggle => // .addToggle(toggle =>
toggle.setValue(settings.indexPDFs).onChange(async v => { // toggle.setValue(settings.indexPDFs).onChange(async v => {
settings.indexPDFs = v // settings.indexPDFs = v
await saveSettings(this.plugin) // await saveSettings(this.plugin)
}) // })
) // )
// Store index // Store index
const serializedIndexDesc = new DocumentFragment() const serializedIndexDesc = new DocumentFragment()

View File

@@ -172,8 +172,12 @@ export function getCtrlKeyLabel(): 'ctrl' | '⌘' {
return Platform.isMacOS ? '⌘' : 'ctrl' return Platform.isMacOS ? '⌘' : 'ctrl'
} }
export function canIndexPDFs(): boolean {
return false
}
export function isFileIndexable(path: string): boolean { 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 { export function isFilePlaintext(path: string): boolean {