From 47f7015215c198fac3d468bb0c1cf893538ca616 Mon Sep 17 00:00:00 2001 From: Rohit Verma Date: Sun, 17 May 2026 18:57:24 +0530 Subject: [PATCH 1/3] fix: optimize loading of additional search results Prevent increasing maxResults to load more search results when there are no more results to fetch. --- src/hooks/useSearchSelector.base.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/hooks/useSearchSelector.base.ts b/src/hooks/useSearchSelector.base.ts index f56a2acc4ffa..972fa1104fa6 100644 --- a/src/hooks/useSearchSelector.base.ts +++ b/src/hooks/useSearchSelector.base.ts @@ -207,10 +207,6 @@ function useSearchSelectorBase({ const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: passthroughPolicyTagListSelector}); const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); - const onListEndReached = useDebounce(() => { - setMaxResults((previous) => previous + maxResultsPerPage); - }, CONST.TIMING.SEARCH_OPTION_LIST_DEBOUNCE_TIME); - const computedSearchTerm = getSearchValueForPhoneOrEmail(debouncedSearchTerm, countryCode); const trimmedSearchInput = debouncedSearchTerm.trim(); @@ -336,6 +332,25 @@ function useSearchSelectorBase({ } })(); + const onListEndReached = useDebounce(() => { + if (!areOptionsInitialized) { + return; + } + + const itemCounts = + (baseOptions.recentReports?.length ?? 0) + + (baseOptions.personalDetails?.length ?? 0) + + (baseOptions.userToInvite ? 1 : 0) + + (baseOptions.currentUserOption ? 1 : 0) + + (baseOptions.workspaceChats?.length ?? 0); + + if (itemCounts < maxResults) { + return; + } + + setMaxResults((previous) => previous + maxResultsPerPage); + }, CONST.TIMING.SEARCH_OPTION_LIST_DEBOUNCE_TIME); + const isOptionSelected = (option: OptionData) => selectedOptions.some((selected) => doOptionsMatch(selected, option)); const searchOptions = { From 19de76a16f997bc055d51744b3655bae3963437a Mon Sep 17 00:00:00 2001 From: Rohit Verma Date: Tue, 19 May 2026 14:44:21 +0530 Subject: [PATCH 2/3] fix: include self DM chat when calculating search results count --- src/hooks/useSearchSelector/base.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hooks/useSearchSelector/base.ts b/src/hooks/useSearchSelector/base.ts index b249970d8972..81559a39ab51 100644 --- a/src/hooks/useSearchSelector/base.ts +++ b/src/hooks/useSearchSelector/base.ts @@ -342,7 +342,8 @@ function useSearchSelectorBase({ (baseOptions.personalDetails?.length ?? 0) + (baseOptions.userToInvite ? 1 : 0) + (baseOptions.currentUserOption ? 1 : 0) + - (baseOptions.workspaceChats?.length ?? 0); + (baseOptions.workspaceChats?.length ?? 0) + + (baseOptions.selfDMChat ? 1 : 0); if (itemCounts < maxResults) { return; From fe9c87d588a4247516f3378cef4a647ca8da79e7 Mon Sep 17 00:00:00 2001 From: Rohit Verma Date: Wed, 20 May 2026 07:55:08 +0530 Subject: [PATCH 3/3] refactor: use type-safe map for options counters --- src/hooks/useSearchSelector/base.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/hooks/useSearchSelector/base.ts b/src/hooks/useSearchSelector/base.ts index 81559a39ab51..de327c8fd613 100644 --- a/src/hooks/useSearchSelector/base.ts +++ b/src/hooks/useSearchSelector/base.ts @@ -332,20 +332,26 @@ function useSearchSelectorBase({ } })(); + const optionsCounters: Required number>> = { + recentReports: (options) => options.recentReports?.length ?? 0, + personalDetails: (options) => options.personalDetails?.length ?? 0, + userToInvite: (options) => (options.userToInvite ? 1 : 0), + currentUserOption: (options) => (options.currentUserOption ? 1 : 0), + workspaceChats: (options) => options.workspaceChats?.length ?? 0, + selfDMChat: (options) => (options.selfDMChat ? 1 : 0), + }; + const onListEndReached = useDebounce(() => { if (!areOptionsInitialized) { return; } - const itemCounts = - (baseOptions.recentReports?.length ?? 0) + - (baseOptions.personalDetails?.length ?? 0) + - (baseOptions.userToInvite ? 1 : 0) + - (baseOptions.currentUserOption ? 1 : 0) + - (baseOptions.workspaceChats?.length ?? 0) + - (baseOptions.selfDMChat ? 1 : 0); + let optionsCount = 0; + for (const optionsCounter of Object.values(optionsCounters)) { + optionsCount += optionsCounter(baseOptions); + } - if (itemCounts < maxResults) { + if (optionsCount < maxResults) { return; }