From c2535b0ebd9115ee0b05d4f3cef9928855c118cd Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Wed, 19 Oct 2022 22:09:55 +0200 Subject: [PATCH] Tweaked values for resources management --- src/search.ts | 4 +--- src/settings.ts | 12 +++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/search.ts b/src/search.ts index 92024c0..8bbd667 100644 --- a/src/search.ts +++ b/src/search.ts @@ -98,7 +98,7 @@ export async function initGlobalSearchIndex(): Promise { } // Read and index all the files into the search engine - const queue = pLimit(10) + const queue = pLimit(settings.backgroundProcesses) const input = [] for (const file of files) { if (cacheManager.getNoteFromMemCache(file.path)) { @@ -136,7 +136,6 @@ export async function initGlobalSearchIndex(): Promise { async function search(query: Query): Promise { if (!query.segmentsToStr()) return [] - console.time('Omnisearch - searching') let results = minisearchInstance.search(query.segmentsToStr(), { prefix: true, fuzzy: term => (term.length > 4 ? 0.2 : false), @@ -149,7 +148,6 @@ async function search(query: Query): Promise { headings3: settings.weightH3, }, }) - console.timeEnd('Omnisearch - searching') // Downrank files that are in Obsidian's excluded list if (settings.respectExcluded) { diff --git a/src/settings.ts b/src/settings.ts index b3cc485..93e8d1b 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -334,14 +334,20 @@ export class SettingsTab extends PluginSettingTab { } } +// Determining the maximum concurrent processes/workers/promises for heavy work, +// without hogging all the resources. +const cpuCount = Platform.isMobileApp ? 1 : require('os').cpus().length +let backgroundProcesses = Math.max(1, Math.floor(cpuCount * 0.75)) +if (backgroundProcesses == cpuCount) { + backgroundProcesses = 1 +} + export const DEFAULT_SETTINGS: OmnisearchSettings = { respectExcluded: true, ignoreDiacritics: true, indexedFileTypes: [] as string[], PDFIndexing: false, - backgroundProcesses: Platform.isMobileApp - ? 1 - : Math.max(1, Math.floor(require('os').cpus().length * 0.75)), + backgroundProcesses, showIndexingNotices: false, showShortName: false,