From fc35658735bcd30c4a5af186008640ef084c90d5 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Fri, 12 Apr 2024 13:16:20 -0400 Subject: [PATCH] Improve getSearchText perf --- src/libs/OptionsListUtils.ts | 37 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 280ba825761f..91b542e7539e 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -432,12 +432,10 @@ function uniqFast(items: string[]): string[] { /** * Returns a string with all relevant search terms. - * Default should be serachable by policy/domain name but not by participants. * * This method must be incredibly performant. It was found to be a big performance bottleneck * when dealing with accounts that have thousands of reports. For loops are more efficient than _.each - * Array.prototype.push.apply is faster than using the spread operator, and concat() is faster than push(). - + * Array.prototype.push.apply is faster than using the spread operator. */ function getSearchText( report: OnyxEntry, @@ -446,22 +444,17 @@ function getSearchText( isChatRoomOrPolicyExpenseChat: boolean, isThread: boolean, ): string { - let searchTerms: string[] = []; - - if (!isChatRoomOrPolicyExpenseChat) { - for (const personalDetail of personalDetailList) { - if (personalDetail.login) { - // The regex below is used to remove dots only from the local part of the user email (local-part@domain) - // so that we can match emails that have dots without explicitly writing the dots (e.g: fistlast@domain will match first.last@domain) - // More info https://github.com/Expensify/App/issues/8007 - searchTerms = searchTerms.concat([ - PersonalDetailsUtils.getDisplayNameOrDefault(personalDetail, '', false), - personalDetail.login, - personalDetail.login.replace(/\.(?=[^\s@]*@)/g, ''), - ]); - } + const searchTerms: string[] = []; + + for (const personalDetail of personalDetailList) { + if (personalDetail.login) { + // The regex below is used to remove dots only from the local part of the user email (local-part@domain) + // so that we can match emails that have dots without explicitly writing the dots (e.g: fistlast@domain will match first.last@domain) + // More info https://github.com/Expensify/App/issues/8007 + searchTerms.push(PersonalDetailsUtils.getDisplayNameOrDefault(personalDetail, '', false), personalDetail.login, personalDetail.login.replace(/\.(?=[^\s@]*@)/g, '')); } } + if (report) { Array.prototype.push.apply(searchTerms, reportName.split(/[,\s]/)); @@ -475,16 +468,6 @@ function getSearchText( const chatRoomSubtitle = ReportUtils.getChatRoomSubtitle(report); Array.prototype.push.apply(searchTerms, chatRoomSubtitle?.split(/[,\s]/) ?? ['']); - } else { - const visibleChatMemberAccountIDs = report.visibleChatMemberAccountIDs ?? []; - if (allPersonalDetails) { - for (const accountID of visibleChatMemberAccountIDs) { - const login = allPersonalDetails[accountID]?.login; - if (login) { - searchTerms = searchTerms.concat(login); - } - } - } } }