From 367e4ce663fdfc0e974a97edfe0558496dfe93ba Mon Sep 17 00:00:00 2001 From: Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:05:10 +0800 Subject: [PATCH] remove background busyspin for the case where concurrency = 1 --- .../hooks/useGlobalSearch.ts | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/screens/GlobalSearchScreen/hooks/useGlobalSearch.ts b/src/screens/GlobalSearchScreen/hooks/useGlobalSearch.ts index 25b1cb7a9..3df9dc9cb 100644 --- a/src/screens/GlobalSearchScreen/hooks/useGlobalSearch.ts +++ b/src/screens/GlobalSearchScreen/hooks/useGlobalSearch.ts @@ -100,21 +100,33 @@ export const useGlobalSearch = ({ defaultSearchText }: Props) => { ); (async () => { - for (let _plugin of filteredSortedInstalledPlugins) { - while (running >= globalSearchConcurrency || !isFocused.current) { - await new Promise(resolve => setTimeout(resolve, 100)); + if (globalSearchConcurrency > 1) { + for (let _plugin of filteredSortedInstalledPlugins) { + while (running >= globalSearchConcurrency || !isFocused.current) { + await new Promise(resolve => setTimeout(resolve, 100)); + } + if (!isMounted.current) { + break; + } + running++; + searchInPlugin(_plugin) + .then(() => { + running--; + }) + .catch(() => { + running--; + }); } - if (!isMounted.current) { - break; + } else { + for (let _plugin of filteredSortedInstalledPlugins) { + if (!isMounted.current) { + break; + } + while (!isFocused.current) { + await new Promise(resolve => setTimeout(resolve, 100)); + } + await searchInPlugin(_plugin); } - running++; - searchInPlugin(_plugin) - .then(() => { - running--; - }) - .catch(() => { - running--; - }); } })(); };