Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/Search/SearchFiltersChatsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import usePrivateIsArchivedMap from '@hooks/usePrivateIsArchivedMap';
import useReportAttributes from '@hooks/useReportAttributes';
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {createOptionFromReport, filterAndOrderOptions, formatSectionsFromSearchTerm, getAlternateText, getSearchOptions} from '@libs/OptionsListUtils';
import type {Option} from '@libs/OptionsListUtils';
import type {OptionWithKey, SelectionListSections} from '@libs/OptionsListUtils/types';
Expand Down Expand Up @@ -64,14 +65,16 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT);
const privateIsArchivedMap = usePrivateIsArchivedMap();
const [nvpDismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING);
const [policyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How abouty using a selector here to narrow down the collection to just the ones matching the selectedReportIDs?


const selectedOptions: OptionData[] = selectedReportIDs.map((id) => {
const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${id}`];
const reportData = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`];
const report = getSelectedOptionData(createOptionFromReport({...reportData, reportID: id}, personalDetails, currentUserAccountID, privateIsArchived, reportAttributesDerived));
const isReportArchived = !!privateIsArchived;
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportData?.policyID}`];
const alternateText = getAlternateText(report, {}, isReportArchived, currentUserEmail, policy, {}, undefined, undefined, reportAttributesDerived);
const reportPolicyTags = policyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(report?.policyID)}`];
const alternateText = getAlternateText(report, {}, isReportArchived, currentUserEmail, policy, {}, undefined, undefined, reportAttributesDerived, reportPolicyTags);
return {...report, alternateText};
});

Expand Down
6 changes: 6 additions & 0 deletions src/hooks/useSearchSelector.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ function useSearchSelectorBase({
const currentUserAccountID = currentUserPersonalDetails.accountID;
const currentUserEmail = currentUserPersonalDetails.email ?? '';
const personalDetails = usePersonalDetails();
const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-11

useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS) subscribes to the entire policy tags collection for ALL policies without a selector. This collection is then added to the baseOptions useMemo dependency array, so any tag change on any policy invalidates the memoized search options and triggers a full recomputation — even if the user's visible reports only belong to one or two policies.

Consider accessing the collection via a ref (useRef updated in a useEffect) so that tag changes do not cause the expensive baseOptions recomputation, or use a selector to narrow down to only the policy IDs relevant to the displayed results.


Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

const onListEndReached = useDebounce(
useCallback(() => {
Expand Down Expand Up @@ -231,6 +232,7 @@ function useSearchSelectorBase({
personalDetails,
countryCode,
reportAttributesDerived: reportAttributesDerived?.reports,
allPolicyTags,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_GENERAL:
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, {
Expand All @@ -246,6 +248,7 @@ function useSearchSelectorBase({
personalDetails,
countryCode,
reportAttributesDerived: reportAttributesDerived?.reports,
allPolicyTags,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_SHARE_DESTINATION:
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, {
Expand All @@ -268,6 +271,7 @@ function useSearchSelectorBase({
personalDetails,
countryCode,
reportAttributesDerived: reportAttributesDerived?.reports,
allPolicyTags,
});
case CONST.SEARCH_SELECTOR.SEARCH_CONTEXT_ATTENDEES:
return getValidOptions(optionsWithContacts, allPolicies, draftComments, nvpDismissedProductTraining, loginList, currentUserAccountID, currentUserEmail, {
Expand All @@ -289,6 +293,7 @@ function useSearchSelectorBase({
personalDetails,
countryCode,
reportAttributesDerived: reportAttributesDerived?.reports,
allPolicyTags,
});
default:
return getEmptyOptions();
Expand Down Expand Up @@ -319,6 +324,7 @@ function useSearchSelectorBase({
personalDetails,
reportAttributesDerived?.reports,
trimmedSearchInput,
allPolicyTags,
]);

const isOptionSelected = useMemo(() => {
Expand Down
Loading
Loading