Skip to content
Merged
5 changes: 4 additions & 1 deletion src/hooks/useFilteredOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import {isTrackIntentUserSelector} from '@selectors/Onboarding';
import {useCallback, useMemo, useState} from 'react';

import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
import useLocalize from './useLocalize';
import useOnyx from './useOnyx';
import usePrivateIsArchivedMap from './usePrivateIsArchivedMap';
Expand Down Expand Up @@ -92,6 +93,7 @@ function useFilteredOptions(config: UseFilteredOptionsConfig = {}): UseFilteredO
// Sorted report actions from the RAM_ONLY_SORTED_REPORT_ACTIONS derived value; a new reference on
// every recompute, so it doubles as the report-actions invalidation signal for the option-list cache.
const sortedActions = useSortedActions();
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();

const privateIsArchivedMap = usePrivateIsArchivedMap();

Expand All @@ -107,7 +109,7 @@ function useFilteredOptions(config: UseFilteredOptionsConfig = {}): UseFilteredO
reportAttributesDerived,
privateIsArchivedMap,
allPolicies,
{dateFnsLocale, conciergeReportID, maxRecentReports: reportsLimit, includeP2P, isSearching, deferContactsUntilSearch, locale: preferredLocale},
{currentUserAccountID, dateFnsLocale, conciergeReportID, maxRecentReports: reportsLimit, includeP2P, isSearching, deferContactsUntilSearch, locale: preferredLocale},
undefined,
undefined,
isTrackIntentUser,
Expand All @@ -129,6 +131,7 @@ function useFilteredOptions(config: UseFilteredOptionsConfig = {}): UseFilteredO
preferredLocale,
isTrackIntentUser,
sortedActions,
currentUserAccountID,
dateFnsLocale,
],
);
Expand Down
9 changes: 8 additions & 1 deletion src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,9 @@ function processReport(
visibleReportActionsData = {},
isTrackIntentUser,
sortedActions,
currentUserAccountID,
}: {
currentUserAccountID: number;
reportAttributesDerived?: ReportAttributesDerivedValue['reports'];
policyTags?: OnyxEntry<PolicyTagLists>;
visibleReportActionsData?: VisibleReportActionsDerivedValue;
Expand Down Expand Up @@ -1641,6 +1643,7 @@ function processReport(
visibleReportActionsData,
isTrackIntentUser,
sortedActions,
currentUserAccountID,
}),
},
};
Expand Down Expand Up @@ -1750,6 +1753,7 @@ function createFilteredOptionList(
privateIsArchivedMap: PrivateIsArchivedMap,
policiesCollection: OnyxCollection<Policy>,
options: {
currentUserAccountID: number;
dateFnsLocale: DateFnsLocale | undefined;
conciergeReportID: string | undefined;
maxRecentReports?: number;
Expand All @@ -1770,7 +1774,7 @@ function createFilteredOptionList(
// TODO: Remove optional (?) once all callers pass sortedActions. Refactor issue: https://github.com/Expensify/App/issues/66381
sortedActions?: Record<string, ReportAction[]>,
): OptionList {
const {conciergeReportID, maxRecentReports = 500, includeP2P = true, isSearching = false, deferContactsUntilSearch = false, locale} = options;
const {currentUserAccountID, conciergeReportID, maxRecentReports = 500, includeP2P = true, isSearching = false, deferContactsUntilSearch = false, locale} = options;

// Contacts are expensive to build on large accounts (one option per personal detail). When a screen
// opts into deferral and is not actively searching, skip building them entirely; the empty state
Expand Down Expand Up @@ -1800,6 +1804,7 @@ function createFilteredOptionList(
// The RAM_ONLY_SORTED_REPORT_ACTIONS derived value produces a new object on every recompute,
// so its reference signals that the underlying report actions changed.
sortedActions,
currentUserAccountID,
];
const cachedEntry = shouldUseCache ? filteredOptionListCache.get(cacheEntryKey) : undefined;
if (cachedEntry && cacheInputs.every((value, index) => value === cachedEntry.inputs.at(index))) {
Expand Down Expand Up @@ -1859,6 +1864,7 @@ function createFilteredOptionList(
visibleReportActionsData,
isTrackIntentUser,
sortedActions,
currentUserAccountID,
});
if (reportMapEntry) {
const [accountID, reportValue] = reportMapEntry;
Expand Down Expand Up @@ -1904,6 +1910,7 @@ function createFilteredOptionList(
reportAttributesDerived,
policyTags: reportPolicyTags,
visibleReportActionsData,
currentUserAccountID,
}),
};
})
Expand Down
5 changes: 5 additions & 0 deletions tests/perf-test/OptionsListUtils.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ jest.mock('@react-navigation/native', () => {
});

const EMPTY_PRIVATE_IS_ARCHIVED_MAP: PrivateIsArchivedMap = {};
const CURRENT_USER_ACCOUNT_ID = 1;
const options = createFilteredOptionList(personalDetails, reports, undefined, EMPTY_PRIVATE_IS_ARCHIVED_MAP, undefined, {
dateFnsLocale: undefined,
conciergeReportID: undefined,
isSearching: true,
currentUserAccountID: CURRENT_USER_ACCOUNT_ID,
});

const ValidOptionsConfig = {
Expand Down Expand Up @@ -296,6 +298,7 @@ describe('OptionsListUtils', () => {
// Inputs are referentially identical across measured runs, so clear the cache to measure the build path.
clearFilteredOptionListCache();
return createFilteredOptionList(personalDetails, mockedReportsMap, undefined, EMPTY_PRIVATE_IS_ARCHIVED_MAP, undefined, {
currentUserAccountID: CURRENT_USER_ACCOUNT_ID,
dateFnsLocale: undefined,
conciergeReportID: undefined,
maxRecentReports: 500,
Expand All @@ -308,6 +311,7 @@ describe('OptionsListUtils', () => {
await waitForBatchedUpdates();
await measureFunction(() =>
createFilteredOptionList(personalDetails, mockedReportsMap, undefined, EMPTY_PRIVATE_IS_ARCHIVED_MAP, undefined, {
currentUserAccountID: CURRENT_USER_ACCOUNT_ID,
dateFnsLocale: undefined,
conciergeReportID: undefined,
maxRecentReports: 500,
Expand All @@ -319,6 +323,7 @@ describe('OptionsListUtils', () => {
test('[OptionsListUtils] getSearchOptions with isSearching is true', async () => {
await waitForBatchedUpdates();
const optionLists = createFilteredOptionList(personalDetails, mockedReportsMap, undefined, EMPTY_PRIVATE_IS_ARCHIVED_MAP, undefined, {
currentUserAccountID: CURRENT_USER_ACCOUNT_ID,
dateFnsLocale: undefined,
conciergeReportID: undefined,
maxRecentReports: 500,
Expand Down
Loading
Loading