Skip to content

Commit

Permalink
Merge pull request #51177 from Expensify/revert-48652-perf/search-suf…
Browse files Browse the repository at this point in the history
…fix-ukkonen-tree

[CP Staging] Revert "Search suffix tree implementation"
  • Loading branch information
jasperhuangg authored Oct 21, 2024
2 parents e8d5313 + a16871f commit 786d037
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 736 deletions.
3 changes: 0 additions & 3 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,9 +1143,6 @@ const CONST = {
SEARCH_OPTION_LIST_DEBOUNCE_TIME: 300,
RESIZE_DEBOUNCE_TIME: 100,
UNREAD_UPDATE_DEBOUNCE_TIME: 300,
SEARCH_CONVERT_SEARCH_VALUES: 'search_convert_search_values',
SEARCH_MAKE_TREE: 'search_make_tree',
SEARCH_BUILD_TREE: 'search_build_tree',
SEARCH_FILTER_OPTIONS: 'search_filter_options',
USE_DEBOUNCED_STATE_DELAY: 300,
},
Expand Down
62 changes: 4 additions & 58 deletions src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import FastSearch from '@libs/FastSearch';
import Log from '@libs/Log';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import {getAllTaxRates} from '@libs/PolicyUtils';
Expand Down Expand Up @@ -64,49 +63,6 @@ function SearchRouter({onRouterClose}: SearchRouterProps) {
return OptionsListUtils.getSearchOptions(options, '', betas ?? []);
}, [areOptionsInitialized, betas, options]);

/**
* Builds a suffix tree and returns a function to search in it.
*/
const findInSearchTree = useMemo(() => {
const fastSearch = FastSearch.createFastSearch([
{
data: searchOptions.personalDetails,
toSearchableString: (option) => {
const displayName = option.participantsList?.[0]?.displayName ?? '';
return [option.login ?? '', option.login !== displayName ? displayName : ''].join();
},
},
{
data: searchOptions.recentReports,
toSearchableString: (option) => {
const searchStringForTree = [option.text ?? '', option.login ?? ''];

if (option.isThread) {
if (option.alternateText) {
searchStringForTree.push(option.alternateText);
}
} else if (!!option.isChatRoom || !!option.isPolicyExpenseChat) {
if (option.subtitle) {
searchStringForTree.push(option.subtitle);
}
}

return searchStringForTree.join();
},
},
]);
function search(searchInput: string) {
const [personalDetails, recentReports] = fastSearch.search(searchInput);

return {
personalDetails,
recentReports,
};
}

return search;
}, [searchOptions.personalDetails, searchOptions.recentReports]);

const filteredOptions = useMemo(() => {
if (debouncedInputValue.trim() === '') {
return {
Expand All @@ -117,25 +73,15 @@ function SearchRouter({onRouterClose}: SearchRouterProps) {
}

Timing.start(CONST.TIMING.SEARCH_FILTER_OPTIONS);
const newOptions = findInSearchTree(debouncedInputValue);
const newOptions = OptionsListUtils.filterOptions(searchOptions, debouncedInputValue, {sortByReportTypeInSearch: true, preferChatroomsOverThreads: true});
Timing.end(CONST.TIMING.SEARCH_FILTER_OPTIONS);

const recentReports = newOptions.recentReports.concat(newOptions.personalDetails);

const userToInvite = OptionsListUtils.pickUserToInvite({
canInviteUser: true,
return {
recentReports: newOptions.recentReports,
personalDetails: newOptions.personalDetails,
searchValue: debouncedInputValue,
optionsToExclude: [{login: CONST.EMAIL.NOTIFICATIONS}],
});

return {
recentReports,
personalDetails: [],
userToInvite,
userToInvite: newOptions.userToInvite,
};
}, [debouncedInputValue, findInSearchTree]);
}, [debouncedInputValue, searchOptions]);

const recentReports: OptionData[] = useMemo(() => {
if (debouncedInputValue === '') {
Expand Down
140 changes: 0 additions & 140 deletions src/libs/FastSearch.ts

This file was deleted.

38 changes: 10 additions & 28 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2419,31 +2419,6 @@ function getPersonalDetailSearchTerms(item: Partial<ReportUtils.OptionData>) {
function getCurrentUserSearchTerms(item: ReportUtils.OptionData) {
return [item.text ?? '', item.login ?? '', item.login?.replace(CONST.EMAIL_SEARCH_REGEX, '') ?? ''];
}

type PickUserToInviteParams = {
canInviteUser: boolean;
recentReports: ReportUtils.OptionData[];
personalDetails: ReportUtils.OptionData[];
searchValue: string;
config?: FilterOptionsConfig;
optionsToExclude: Option[];
};

const pickUserToInvite = ({canInviteUser, recentReports, personalDetails, searchValue, config, optionsToExclude}: PickUserToInviteParams) => {
let userToInvite = null;
if (canInviteUser) {
if (recentReports.length === 0 && personalDetails.length === 0) {
userToInvite = getUserToInviteOption({
searchValue,
selectedOptions: config?.selectedOptions,
optionsToExclude,
});
}
}

return userToInvite;
};

/**
* Filters options based on the search input value
*/
Expand Down Expand Up @@ -2531,7 +2506,16 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt
recentReports = orderOptions(recentReports, searchValue);
}

const userToInvite = pickUserToInvite({canInviteUser, recentReports, personalDetails, searchValue, config, optionsToExclude});
let userToInvite = null;
if (canInviteUser) {
if (recentReports.length === 0 && personalDetails.length === 0) {
userToInvite = getUserToInviteOption({
searchValue,
selectedOptions: config?.selectedOptions,
optionsToExclude,
});
}
}

if (maxRecentReportsToShow > 0 && recentReports.length > maxRecentReportsToShow) {
recentReports.splice(maxRecentReportsToShow);
Expand Down Expand Up @@ -2600,7 +2584,6 @@ export {
formatMemberForList,
formatSectionsFromSearchTerm,
getShareLogOptions,
orderOptions,
filterOptions,
createOptionList,
createOptionFromReport,
Expand All @@ -2614,7 +2597,6 @@ export {
getEmptyOptions,
shouldUseBoldText,
getAlternateText,
pickUserToInvite,
hasReportErrors,
};

Expand Down
Loading

0 comments on commit 786d037

Please sign in to comment.