@@ -18,7 +18,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
1818import { getCardFeedKey , getCardFeedNamesWithType } from '@libs/CardFeedUtils' ;
1919import { getCardDescription , isCard , isCardHiddenFromSearch , mergeCardListWithWorkspaceFeeds } from '@libs/CardUtils' ;
2020import memoize from '@libs/memoize' ;
21- import { getMostRecentOptions , Options , SearchOption } from '@libs/OptionsListUtils' ;
21+ import { getMostRecentOptions , Options , recentReportComparator , SearchOption } from '@libs/OptionsListUtils' ;
2222import { combineOrderingOfReportsAndPersonalDetails , getSearchOptions , getValidPersonalDetailOptions , orderReportOptions } from '@libs/OptionsListUtils' ;
2323import Performance from '@libs/Performance' ;
2424import { getAllTaxRates , getCleanedTagName , shouldShowPolicy } from '@libs/PolicyUtils' ;
@@ -353,14 +353,10 @@ function SearchAutocompleteList(
353353 } ) ) ;
354354 }
355355 case CONST . SEARCH . SYNTAX_FILTER_KEYS . IN : {
356- Timing . start ( CONST . TIMING . SEARCH_MOST_RECENT_OPTIONS )
357-
358356 // const orderedReportOptions = orderReportOptions(searchOptions.recentReports);
359- const orderedReportOptions = getMostRecentOptions ( searchOptions . recentReports , 10 )
360- const filteredChats = orderedReportOptions
361- . filter ( ( chat ) => chat . text ?. toLowerCase ( ) ?. includes ( autocompleteValue . toLowerCase ( ) ) && ! alreadyAutocompletedKeys . includes ( chat . text . toLowerCase ( ) ) )
362- . slice ( 0 , 10 ) ;
363- Timing . end ( CONST . TIMING . SEARCH_MOST_RECENT_OPTIONS )
357+ const filterChats = ( chat : OptionData ) => chat . text ?. toLowerCase ( ) ?. includes ( autocompleteValue . toLowerCase ( ) ) && ! alreadyAutocompletedKeys . includes ( chat . text . toLowerCase ( ) ) ;
358+ const filteredChats = getMostRecentOptions ( searchOptions . recentReports , 10 , recentReportComparator , filterChats ) ;
359+
364360 return filteredChats . map ( ( chat ) => ( {
365361 filterKey : CONST . SEARCH . SEARCH_USER_FRIENDLY_KEYS . IN ,
366362 text : chat . text ?? '' ,
@@ -501,12 +497,13 @@ function SearchAutocompleteList(
501497 const { search : filterOptions , isInitialized : isFastSearchInitialized } = useFastSearchFromOptions ( searchOptions , { includeUserToInvite : true } ) ;
502498
503499 const recentReportsOptions = useMemo ( ( ) => {
500+ Timing . start ( CONST . TIMING . SEARCH_FILTER_OPTIONS ) ;
504501 if ( autocompleteQueryValue . trim ( ) === '' || ! isFastSearchInitialized ) {
505- const orderedReportOptions = orderReportOptions ( searchOptions . recentReports ) ;
506- return orderedReportOptions . slice ( 0 , 20 ) ;
502+ const orderedReportOptions = getMostRecentOptions ( searchOptions . recentReports , 20 , recentReportComparator ) ;
503+ Timing . end ( CONST . TIMING . SEARCH_FILTER_OPTIONS ) ;
504+ return orderedReportOptions ;
507505 }
508506
509- Timing . start ( CONST . TIMING . SEARCH_FILTER_OPTIONS ) ;
510507 const filteredOptions = filterOptions ( autocompleteQueryValue ) ;
511508 const orderedOptions = combineOrderingOfReportsAndPersonalDetails ( filteredOptions , autocompleteQueryValue , {
512509 sortByReportTypeInSearch : true ,
0 commit comments