#349 - Added a "danger" setting to disable the cache killswitch

This commit is contained in:
Simon Cambier
2024-06-27 21:25:06 +02:00
parent 87d2085fda
commit 3611884bc5
2 changed files with 35 additions and 10 deletions

View File

@@ -137,7 +137,9 @@ export default class OmnisearchPlugin extends Plugin {
}) })
) )
this.refreshIndexCallback = this.notesIndexer.refreshIndex.bind(this.notesIndexer) this.refreshIndexCallback = this.notesIndexer.refreshIndex.bind(
this.notesIndexer
)
addEventListener('blur', this.refreshIndexCallback) addEventListener('blur', this.refreshIndexCallback)
removeEventListener removeEventListener
@@ -263,16 +265,21 @@ export default class OmnisearchPlugin extends Plugin {
indexingStep.set(IndexingStepType.WritingCache) indexingStep.set(IndexingStepType.WritingCache)
// Disable settings.useCache while writing the cache, in case it freezes // Disable settings.useCache while writing the cache, in case it freezes
const cacheEnabled = this.settings.useCache
if (cacheEnabled && !this.settings.DANGER_forceSaveCache) {
this.settings.useCache = false this.settings.useCache = false
await saveSettings(this) await saveSettings(this)
}
// Write the cache // Write the cache
await searchEngine.writeToCache() await searchEngine.writeToCache()
// Re-enable settings.caching // Re-enable settings.caching
if (cacheEnabled) {
this.settings.useCache = true this.settings.useCache = true
await saveSettings(this) await saveSettings(this)
} }
}
console.timeEnd('Omnisearch - Indexing total time') console.timeEnd('Omnisearch - Indexing total time')
if (diff.toAdd.length >= 1000 && isCacheEnabled()) { if (diff.toAdd.length >= 1000 && isCacheEnabled()) {

View File

@@ -11,7 +11,7 @@ import {
import { writable } from 'svelte/store' import { writable } from 'svelte/store'
import { K_DISABLE_OMNISEARCH } from './globals' import { K_DISABLE_OMNISEARCH } from './globals'
import type OmnisearchPlugin from './main' import type OmnisearchPlugin from './main'
import { enablePrintDebug } from "./tools/utils"; import { enablePrintDebug } from './tools/utils'
interface WeightingSettings { interface WeightingSettings {
weightBasename: number weightBasename: number
@@ -71,6 +71,7 @@ export interface OmnisearchSettings extends WeightingSettings {
httpApiNotice: boolean httpApiNotice: boolean
DANGER_httpHost: string | null DANGER_httpHost: string | null
DANGER_forceSaveCache: boolean
} }
/** /**
@@ -139,9 +140,7 @@ export class SettingsTab extends PluginSettingTab {
span.innerHTML = `Omnisearch will use Text Extractor to index the content of your PDFs.` span.innerHTML = `Omnisearch will use Text Extractor to index the content of your PDFs.`
}) })
new Setting(containerEl) new Setting(containerEl)
.setName( .setName(`PDFs content indexing ${textExtractor ? '' : '⚠️ Disabled'}`)
`PDFs content indexing ${textExtractor ? '' : '⚠️ Disabled'}`
)
.setDesc(indexPDFsDesc) .setDesc(indexPDFsDesc)
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(settings.PDFIndexing).onChange(async v => { toggle.setValue(settings.PDFIndexing).onChange(async v => {
@@ -695,6 +694,23 @@ export class SettingsTab extends PluginSettingTab {
}) })
) )
// Force save cache
const forceSaveCacheDesc = new DocumentFragment()
forceSaveCacheDesc.createSpan({}, span => {
span.innerHTML = `Omnisearch has a security feature that automatically disables cache writing if it cannot fully perform the operation.<br>
Use this option to force the cache to be saved, even if it causes a crash.<br>
⚠️ <span style="color: var(--text-accent)">Enabling this setting could lead to crash loops</span>`
})
new Setting(containerEl)
.setName('Force save the cache')
.setDesc(forceSaveCacheDesc)
.addToggle(toggle =>
toggle.setValue(settings.DANGER_forceSaveCache).onChange(async v => {
settings.DANGER_forceSaveCache = v
await saveSettings(this.plugin)
})
)
// Clear cache data // Clear cache data
if (isCacheEnabled()) { if (isCacheEnabled()) {
const resetCacheDesc = new DocumentFragment() const resetCacheDesc = new DocumentFragment()
@@ -713,6 +729,7 @@ export class SettingsTab extends PluginSettingTab {
}) })
}) })
} }
//#endregion Danger Zone //#endregion Danger Zone
} }
@@ -769,6 +786,7 @@ export function getDefaultSettings(app: App): OmnisearchSettings {
verboseLogging: false, verboseLogging: false,
DANGER_httpHost: null, DANGER_httpHost: null,
DANGER_forceSaveCache: false,
} }
} }