diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx index 54113abbebe4..e90e1e05fb5a 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx @@ -171,6 +171,7 @@ function OptionRowLHNData({ movedToReport, currentUserAccountID, reportAttributesDerived, + visibleReportActionsData, policyTags, currentUserLogin: login ?? '', isTrackIntentUser, diff --git a/src/components/Search/SearchAutocompleteList.tsx b/src/components/Search/SearchAutocompleteList.tsx index c9cd8a02d950..a538a7d3b939 100644 --- a/src/components/Search/SearchAutocompleteList.tsx +++ b/src/components/Search/SearchAutocompleteList.tsx @@ -1,4 +1,4 @@ -import {usePersonalDetails, useCardList, useWorkspaceCardList} from '@components/OnyxListItemProvider'; +import {usePersonalDetails} from '@components/OnyxListItemProvider'; import OptionsListSkeletonView from '@components/OptionsListSkeletonView'; import type {AnimatedTextInputRef} from '@components/RNTextInput'; import BareUserListItem from '@components/SelectionList/ListItem/BareUserListItem'; @@ -190,8 +190,6 @@ function SearchAutocompleteList({ const isDefaultRoomsBetaEnabled = isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS); const feedKeysWithCards = useFeedKeysWithAssignedCards(); const reportAttributes = useReportAttributes(); - const cardList = useCardList(); - const workspaceCardList = useWorkspaceCardList(); const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT); const [recentSearches, recentSearchesMetadata] = useOnyx(ONYXKEYS.RECENT_SEARCHES); const [countryCode] = useOnyx(ONYXKEYS.COUNTRY_CODE); @@ -290,8 +288,6 @@ function SearchAutocompleteList({ transactionThreadIDs, lastActions, currentUserLogin: currentUserEmail, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, conciergeReportID, @@ -315,8 +311,6 @@ function SearchAutocompleteList({ sortedActions, transactionThreadIDs, lastActions, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, conciergeReportID, diff --git a/src/hooks/useAutocompleteSuggestions.ts b/src/hooks/useAutocompleteSuggestions.ts index 22f037a5a73a..e13ec50f8b5d 100644 --- a/src/hooks/useAutocompleteSuggestions.ts +++ b/src/hooks/useAutocompleteSuggestions.ts @@ -1,5 +1,4 @@ import type {LocaleContextProps} from '@components/LocaleContextProvider'; -import {useCardList, useWorkspaceCardList} from '@components/OnyxListItemProvider'; import type {SubstitutionMap} from '@components/Search/SearchRouter/getQueryWithSubstitutions'; import {getSubstitutionMapKey, getSubstitutionMapKeyWithIndex} from '@components/Search/SearchRouter/getQueryWithSubstitutions'; import type {SearchFilterKey, UserFriendlyKey} from '@components/Search/types'; @@ -134,8 +133,6 @@ function useAutocompleteSuggestions({ const [allPoliciesTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS); const [allRecentTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS); const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); - const cardList = useCardList(); - const workspaceCardList = useWorkspaceCardList(); const sortedReportActionsData = useSortedReportActionsData(); const sortedActions = sortedReportActionsData?.sortedActions; const transactionThreadIDs = sortedReportActionsData?.transactionThreadIDs; @@ -284,8 +281,6 @@ function useAutocompleteSuggestions({ sortedActions, transactionThreadIDs, lastActions, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, conciergeReportID, @@ -336,8 +331,6 @@ function useAutocompleteSuggestions({ sortedActions, transactionThreadIDs, lastActions, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, conciergeReportID, diff --git a/src/hooks/useSearchSelector/base.ts b/src/hooks/useSearchSelector/base.ts index 5f1b07008c7f..c3c7491718e6 100644 --- a/src/hooks/useSearchSelector/base.ts +++ b/src/hooks/useSearchSelector/base.ts @@ -1,4 +1,4 @@ -import {usePersonalDetails, useCardList, useWorkspaceCardList} from '@components/OnyxListItemProvider'; +import {usePersonalDetails} from '@components/OnyxListItemProvider'; import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; @@ -206,8 +206,6 @@ function useSearchSelectorBase({ const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const currentUserAccountID = currentUserPersonalDetails.accountID; const currentUserEmail = currentUserPersonalDetails.email ?? ''; - const cardList = useCardList(); - const workspaceCardList = useWorkspaceCardList(); const personalDetails = usePersonalDetails(); const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS); const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); @@ -313,8 +311,6 @@ function useSearchSelectorBase({ transactionThreadIDs, lastActions, currentUserLogin: currentUserEmail, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, conciergeReportID, @@ -356,8 +352,6 @@ function useSearchSelectorBase({ sortedActions, transactionThreadIDs, lastActions, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, isTrackIntentUser, @@ -403,8 +397,6 @@ function useSearchSelectorBase({ sortedActions, transactionThreadIDs, lastActions, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, isTrackIntentUser, @@ -447,8 +439,6 @@ function useSearchSelectorBase({ sortedActions, transactionThreadIDs, lastActions, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, isTrackIntentUser, diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index 34a4d75c3a81..f3e589e038a7 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -29,9 +29,9 @@ import { getSubmitToAccountID, isTimeTrackingEnabled, } from '@libs/PolicyUtils'; -import {getIOUReportIDFromReportActionPreview, getOneTransactionThreadReportID, isActionOfType, isCardIssuedAction} from '@libs/ReportActionsUtils'; +import {getIOUReportIDFromReportActionPreview, getOneTransactionThreadReportID, isActionOfType} from '@libs/ReportActionsUtils'; import type {LastActionContext} from '@libs/ReportAlternateTextUtils'; -import {getExpensifyCardFromReportAction, getLastMessageTextForReport, getReportAlternateText, resolveLastActionContext} from '@libs/ReportAlternateTextUtils'; +import {getLastMessageTextForReport, getReportAlternateText, resolveLastActionContext} from '@libs/ReportAlternateTextUtils'; import {getReportName} from '@libs/ReportNameUtils'; import type {OptionData} from '@libs/ReportUtils'; import { @@ -76,7 +76,6 @@ import CONST from '@src/CONST'; import IntlStore from '@src/languages/IntlStore'; import ONYXKEYS from '@src/ONYXKEYS'; import type { - CardList, Locale, Login, OnyxInputOrEntry, @@ -92,7 +91,6 @@ import type { ReportAttributesDerivedValue, Rule, VisibleReportActionsDerivedValue, - WorkspaceCardsList, } from '@src/types/onyx'; import type {Participant} from '@src/types/onyx/IOU'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; @@ -253,8 +251,6 @@ type GetAlternateTextConfig = { // TODO: Remove optional (?) once all callers pass currentUserAccountID. Refactor issue: https://github.com/Expensify/App/issues/66408 currentUserAccountID?: number; currentUserLogin?: string; - cardList?: OnyxEntry; - workspaceCardList?: OnyxCollection; localeCompare?: LocaleContextProps['localeCompare']; formatPhoneNumber?: LocaleContextProps['formatPhoneNumber']; /** Resolved by the caller when it already did the lookup, so the last-action scan is not repeated here. */ @@ -302,8 +298,6 @@ function getAlternateText( isTrackIntentUser, currentUserAccountID, currentUserLogin, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, lastActionContext, @@ -324,22 +318,12 @@ function getAlternateText( const oneTransactionThreadReportID = transactionThreadIDs?.[report.reportID]; const {lastAction, lastActionReport, movedFromReport, movedToReport} = lastActionContext ?? resolveLastActionContext(report, isReportArchived, visibleReportActionsData, oneTransactionThreadReportID); - const card = isCardIssuedAction(lastAction) - ? getExpensifyCardFromReportAction({ - reportAction: lastAction, - policy, - cardList, - workspaceCardList, - }) - : undefined; return getReportAlternateText({ report, lastAction, lastActionReport, movedFromReport, movedToReport, - card, - lastMessageTextFromReport: option.lastMessageText, personalDetails, policy, invoiceReceiverPolicy, @@ -2100,6 +2084,12 @@ registerSessionCleanupCallback(() => { alternateTextCacheInputs = undefined; }); +/** Clears the preview cache. For tests that measure or exercise the resolve path while the guarded inputs keep their identity. */ +function clearAlternateTextCache() { + alternateTextCache.clear(); + alternateTextCacheInputs = undefined; +} + /** Drops every cached preview as soon as any input that feeds `getAlternateText` changes identity. */ function syncAlternateTextCache(inputs: unknown[]) { if (alternateTextCacheInputs?.length === inputs.length && inputs.every((input, index) => input === alternateTextCacheInputs?.at(index))) { @@ -2156,8 +2146,6 @@ function prepareReportOptionsForDisplay( dateFnsLocale: DateFnsLocale | undefined; currentUserAccountID?: number; currentUserLogin?: string; - cardList?: OnyxEntry; - workspaceCardList?: OnyxCollection; localeCompare?: LocaleContextProps['localeCompare']; formatPhoneNumber?: LocaleContextProps['formatPhoneNumber']; transactionThreadIDs?: Record; @@ -2189,8 +2177,6 @@ function prepareReportOptionsForDisplay( convertToDisplayStringWithoutCurrency, currentUserAccountID, currentUserLogin, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, transactionThreadIDs, @@ -2212,8 +2198,6 @@ function prepareReportOptionsForDisplay( transactionThreadIDs, lastActions, rules, - cardList, - workspaceCardList, conciergeReportID, isTrackIntentUser, currentUserAccountID, @@ -2270,8 +2254,6 @@ function prepareReportOptionsForDisplay( isTrackIntentUser, currentUserAccountID, currentUserLogin, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, rules, @@ -2385,8 +2367,6 @@ function getValidOptions( transactionThreadIDs, lastActions, currentUserLogin, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, isTrackIntentUser, @@ -2538,8 +2518,6 @@ function getValidOptions( translate, currentUserAccountID, currentUserLogin: currentUserLogin ?? currentUserEmail, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, transactionThreadIDs, @@ -2574,8 +2552,6 @@ function getValidOptions( translate, currentUserAccountID, currentUserLogin: currentUserLogin ?? currentUserEmail, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, transactionThreadIDs, @@ -2606,8 +2582,6 @@ function getValidOptions( translate, currentUserAccountID, currentUserLogin: currentUserLogin ?? currentUserEmail, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, transactionThreadIDs, @@ -2787,8 +2761,6 @@ type SearchOptionsConfig = { transactionThreadIDs?: Record; lastActions?: Record; currentUserLogin?: string; - cardList?: OnyxEntry; - workspaceCardList?: OnyxCollection; localeCompare?: LocaleContextProps['localeCompare']; formatPhoneNumber?: LocaleContextProps['formatPhoneNumber']; conciergeReportID: string | undefined; @@ -2828,8 +2800,6 @@ function getSearchOptions({ transactionThreadIDs, lastActions, currentUserLogin, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, conciergeReportID, @@ -2880,8 +2850,6 @@ function getSearchOptions({ transactionThreadIDs, lastActions, currentUserLogin: currentUserLogin ?? currentUserEmail, - cardList, - workspaceCardList, localeCompare, formatPhoneNumber, excludeFromSuggestionsOnly, @@ -3419,6 +3387,7 @@ function processSearchString(searchString: string | undefined): string[] { export { canCreateOptimisticPersonalDetailOption, + clearAlternateTextCache, clearFilteredOptionListCache, combineOrderingOfReportsAndPersonalDetails, createOptionFromReport, diff --git a/src/libs/OptionsListUtils/types.ts b/src/libs/OptionsListUtils/types.ts index 1694bb66e56a..66f5da21abae 100644 --- a/src/libs/OptionsListUtils/types.ts +++ b/src/libs/OptionsListUtils/types.ts @@ -9,7 +9,6 @@ import type {AvatarSource} from '@libs/UserAvatarUtils'; import type {IOUAction} from '@src/CONST'; import type { - CardList, Login, PersonalDetails, PersonalDetailsList, @@ -21,7 +20,6 @@ import type { ReportAttributesDerivedValue, TransactionViolation, VisibleReportActionsDerivedValue, - WorkspaceCardsList, } from '@src/types/onyx'; import type {Icon, PendingAction} from '@src/types/onyx/OnyxCommon'; @@ -291,8 +289,6 @@ type GetOptionsConfig = { transactionThreadIDs?: Record; lastActions?: Record; currentUserLogin?: string; - cardList?: OnyxEntry; - workspaceCardList?: OnyxCollection; localeCompare?: LocaleContextProps['localeCompare']; formatPhoneNumber?: LocaleContextProps['formatPhoneNumber']; isTrackIntentUser?: boolean; diff --git a/src/libs/ReportAlternateTextUtils.ts b/src/libs/ReportAlternateTextUtils.ts index 093e34bee69a..e3b382c1aa25 100644 --- a/src/libs/ReportAlternateTextUtils.ts +++ b/src/libs/ReportAlternateTextUtils.ts @@ -1151,7 +1151,7 @@ type GetReportAlternateTextParams = { lastActionReport: OnyxEntry; movedFromReport?: OnyxEntry; movedToReport?: OnyxEntry; - card: Card | undefined; + card?: Card | undefined; lastMessageTextFromReport?: string; personalDetails: OnyxEntry; policy: OnyxEntry; diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index ee5846a31836..956a15f5adcf 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -902,6 +902,7 @@ function getOptionData({ conciergeReportID, reportAttributesDerived, visibleReportActionsData, + oneTransactionThreadReportID: reportAttributes?.oneTransactionThreadReportID, currentUserAccountID, currentUserLogin, isTrackIntentUser, diff --git a/tests/perf-test/OptionsListChatPreview.perf-test.ts b/tests/perf-test/OptionsListChatPreview.perf-test.ts index 5e7b068e0df6..e6f4e0fd14ac 100644 --- a/tests/perf-test/OptionsListChatPreview.perf-test.ts +++ b/tests/perf-test/OptionsListChatPreview.perf-test.ts @@ -1,6 +1,6 @@ import type {PrivateIsArchivedMap} from '@hooks/usePrivateIsArchivedMap'; -import {clearFilteredOptionListCache, createFilteredOptionList, getValidOptions} from '@libs/OptionsListUtils'; +import {clearAlternateTextCache, clearFilteredOptionListCache, createFilteredOptionList, getValidOptions} from '@libs/OptionsListUtils'; import {buildParticipantsFromAccountIDs} from '@libs/ReportUtils'; import CONST from '@src/CONST'; @@ -325,4 +325,44 @@ describe('OptionsListChatPreview', () => { ), ); }); + + test('[OptionsListChatPreview] getValidOptions with chat previews, preview cache cold', async () => { + await waitForBatchedUpdates(); + const optionList = buildOptionList(); + await measureFunction(() => { + clearAlternateTextCache(); + return getValidOptions( + {reports: optionList.reports, personalDetails: optionList.personalDetails}, + allPolicies, + {}, + loginList, + CURRENT_USER_ACCOUNT_ID, + CURRENT_USER_EMAIL, + undefined, + getPreviewOptionsConfig(MAX_ELEMENTS), + translateLocal, + undefined, + ); + }); + }); + + test('[OptionsListChatPreview] getValidOptions with chat previews and a wider result cap, preview cache cold', async () => { + await waitForBatchedUpdates(); + const optionList = buildOptionList(); + await measureFunction(() => { + clearAlternateTextCache(); + return getValidOptions( + {reports: optionList.reports, personalDetails: optionList.personalDetails}, + allPolicies, + {}, + loginList, + CURRENT_USER_ACCOUNT_ID, + CURRENT_USER_EMAIL, + undefined, + getPreviewOptionsConfig(WIDE_MAX_ELEMENTS), + translateLocal, + undefined, + ); + }); + }); }); diff --git a/tests/unit/LhnSearchPreviewParityTest.ts b/tests/unit/LhnSearchPreviewParityTest.ts index 25e1a9e8c72b..5b38199b4820 100644 --- a/tests/unit/LhnSearchPreviewParityTest.ts +++ b/tests/unit/LhnSearchPreviewParityTest.ts @@ -425,7 +425,6 @@ async function computeBothSurfaces({ sortedActions: sortedData?.sortedActions, transactionThreadIDs: sortedData?.transactionThreadIDs, lastActions: sortedData?.lastActions, - cardList, localeCompare, formatPhoneNumber, conciergeReportID: CONCIERGE_REPORT_ID,