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()
})
showWelcomeNotice(this)
// showWelcomeNotice(this)
}
onunload(): void {}

View File

@@ -9,6 +9,7 @@ import {
SPACE_OR_PUNCTUATION,
} from './globals'
import {
canIndexPDFs,
isFilePlaintext,
removeDiacritics,
stringsToRegex,
@@ -100,14 +101,18 @@ export async function initGlobalSearchIndex(): Promise<void> {
// This is basically the same behavior as MiniSearch's `addAllAsync()`.
// 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) {
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<void> {
}
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<void>[] = []
let promises: Promise<void>[] = []
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)

View File

@@ -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.<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>`
})
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.<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>`
// })
// 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()

View File

@@ -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 {