Repository navigation
perf: optimize LHN renderItem and sidebar sorting #84734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
54dde52
49a86dd
aa211dd
40ac61d
a91b37e
c8e6c8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -207,7 +207,7 @@ | |||||||||||
|
|
||||||||||||
| let allReports: OnyxCollection<Report>; | ||||||||||||
| Onyx.connect({ | ||||||||||||
| key: ONYXKEYS.COLLECTION.REPORT, | ||||||||||||
|
Check warning on line 210 in src/libs/OptionsListUtils/index.ts
|
||||||||||||
| waitForCollectionCallback: true, | ||||||||||||
| callback: (value) => { | ||||||||||||
| allReports = value; | ||||||||||||
|
|
@@ -216,7 +216,7 @@ | |||||||||||
|
|
||||||||||||
| let allReportNameValuePairsOnyxConnect: OnyxCollection<ReportNameValuePairs>; | ||||||||||||
| Onyx.connect({ | ||||||||||||
| key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, | ||||||||||||
|
Check warning on line 219 in src/libs/OptionsListUtils/index.ts
|
||||||||||||
| waitForCollectionCallback: true, | ||||||||||||
| callback: (value) => { | ||||||||||||
| allReportNameValuePairsOnyxConnect = value; | ||||||||||||
|
|
@@ -225,9 +225,10 @@ | |||||||||||
|
|
||||||||||||
| const lastReportActions: ReportActions = {}; | ||||||||||||
| const allSortedReportActions: Record<string, ReportAction[]> = {}; | ||||||||||||
| const cachedOneTransactionThreadReportIDs: Record<string, string | undefined> = {}; | ||||||||||||
| let allReportActions: OnyxCollection<ReportActions>; | ||||||||||||
| Onyx.connect({ | ||||||||||||
| key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, | ||||||||||||
|
Check warning on line 231 in src/libs/OptionsListUtils/index.ts
|
||||||||||||
| waitForCollectionCallback: true, | ||||||||||||
| callback: (actions) => { | ||||||||||||
| if (!actions) { | ||||||||||||
|
|
@@ -251,7 +252,10 @@ | |||||||||||
|
|
||||||||||||
| // If the report is a one-transaction report, we need to return the combined reportActions so that the LHN can display modifications | ||||||||||||
| // to the transaction thread or the report itself. | ||||||||||||
| // Cache the result for O(1) lookup in renderItem. | ||||||||||||
| const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, actions[reportActions[0]]); | ||||||||||||
| cachedOneTransactionThreadReportIDs[reportID] = transactionThreadReportID; | ||||||||||||
|
|
||||||||||||
| if (transactionThreadReportID) { | ||||||||||||
| const transactionThreadReportActionsArray = Object.values(actions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`] ?? {}); | ||||||||||||
| sortedReportActions = getCombinedReportActions(sortedReportActions, transactionThreadReportID, transactionThreadReportActionsArray, reportID); | ||||||||||||
|
|
@@ -269,7 +273,7 @@ | |||||||||||
|
|
||||||||||||
| let activePolicyID: OnyxEntry<string>; | ||||||||||||
| Onyx.connect({ | ||||||||||||
| key: ONYXKEYS.NVP_ACTIVE_POLICY_ID, | ||||||||||||
|
Check warning on line 276 in src/libs/OptionsListUtils/index.ts
|
||||||||||||
| callback: (value) => (activePolicyID = value), | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
|
|
@@ -433,8 +437,6 @@ | |||||||||||
| reportAttributesDerived?: ReportAttributesDerivedValue['reports'], | ||||||||||||
| ) { | ||||||||||||
| const report = getReportOrDraftReport(option.reportID); | ||||||||||||
| // TODO: This allReports usage is temporary and will be removed once the full Onyx.connect() refactor is complete (https://github.com/Expensify/App/issues/66378) | ||||||||||||
| const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; | ||||||||||||
| const isAdminRoom = reportUtilsIsAdminRoom(report); | ||||||||||||
| const isAnnounceRoom = reportUtilsIsAnnounceRoom(report); | ||||||||||||
| const isGroupChat = reportUtilsIsGroupChat(report); | ||||||||||||
|
|
@@ -449,7 +451,6 @@ | |||||||||||
| lastActorDetails, | ||||||||||||
| policy, | ||||||||||||
| isReportArchived, | ||||||||||||
| chatReport, | ||||||||||||
| visibleReportActionsDataParam: visibleReportActionsData, | ||||||||||||
| reportAttributesDerived, | ||||||||||||
| currentUserLogin, | ||||||||||||
|
|
@@ -597,7 +598,6 @@ | |||||||||||
| policy, | ||||||||||||
| isReportArchived = false, | ||||||||||||
| policyForMovingExpensesID, | ||||||||||||
| chatReport, | ||||||||||||
| reportMetadata, | ||||||||||||
| visibleReportActionsDataParam, | ||||||||||||
| lastAction, | ||||||||||||
|
|
@@ -613,7 +613,6 @@ | |||||||||||
| policy?: OnyxEntry<Policy>; | ||||||||||||
| isReportArchived?: boolean; | ||||||||||||
| policyForMovingExpensesID?: string; | ||||||||||||
| chatReport?: OnyxEntry<Report>; | ||||||||||||
| reportMetadata?: OnyxEntry<ReportMetadata>; | ||||||||||||
| visibleReportActionsDataParam?: VisibleReportActionsDerivedValue; | ||||||||||||
| lastAction?: OnyxEntry<ReportAction>; | ||||||||||||
|
|
@@ -625,8 +624,7 @@ | |||||||||||
| const canUserPerformWrite = canUserPerformWriteAction(report, isReportArchived); | ||||||||||||
| let lastReportAction = lastAction ?? getLastVisibleAction(reportID, canUserPerformWrite, {}, undefined, visibleReportActionsDataParam); | ||||||||||||
|
|
||||||||||||
| const chatReportForTransactionThread = chatReport ?? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; | ||||||||||||
| const transactionThreadReportID = reportID ? getOneTransactionThreadReportID(report, chatReportForTransactionThread, allSortedReportActions[reportID]) : undefined; | ||||||||||||
| const transactionThreadReportID = reportID ? cachedOneTransactionThreadReportIDs[reportID] : undefined; | ||||||||||||
|
|
||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
App/src/libs/ReportActionsUtils.ts Lines 1808 to 1812 in 0ff5265
This flow test well though
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed. The cache is populated in the REPORT_ACTIONS Onyx callback which already has access to allReports, so chatReport is resolved there. The only edge case would be a chatReportID update without a corresponding REPORT_ACTIONS change, but that does not happen in practice since chatReportID is set at report creation time. |
||||||||||||
| if (reportID && !lastAction && transactionThreadReportID) { | ||||||||||||
| lastReportAction = | ||||||||||||
|
|
@@ -953,7 +951,6 @@ | |||||||||||
| personalDetails: OnyxInputOrEntry<PersonalDetailsList>, | ||||||||||||
| report: OnyxInputOrEntry<Report>, | ||||||||||||
| currentUserAccountID: number, | ||||||||||||
| chatReport: OnyxEntry<Report>, | ||||||||||||
| config?: PreviewConfig, | ||||||||||||
| reportAttributesDerived?: ReportAttributesDerivedValue['reports'], | ||||||||||||
| privateIsArchived?: string, | ||||||||||||
|
|
@@ -1042,7 +1039,6 @@ | |||||||||||
| report, | ||||||||||||
| lastActorDetails, | ||||||||||||
| isReportArchived: !!result.private_isArchived, | ||||||||||||
| chatReport, | ||||||||||||
| visibleReportActionsDataParam: visibleReportActionsData, | ||||||||||||
| reportAttributesDerived, | ||||||||||||
| currentUserLogin, | ||||||||||||
|
|
@@ -1117,16 +1113,13 @@ | |||||||||||
| visibleReportActionsData: VisibleReportActionsDerivedValue = {}, | ||||||||||||
| ): OptionData { | ||||||||||||
| const report = getReportOrDraftReport(participant.reportID, undefined, undefined, reportDrafts); | ||||||||||||
| // TODO: This allReports usage is temporary and will be removed once the full Onyx.connect() refactor is complete (https://github.com/Expensify/App/issues/66378) | ||||||||||||
| const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; | ||||||||||||
| const visibleParticipantAccountIDs = getParticipantsAccountIDsForDisplay(report, true); | ||||||||||||
|
|
||||||||||||
| const option = createOption( | ||||||||||||
| visibleParticipantAccountIDs, | ||||||||||||
| personalDetails ?? {}, | ||||||||||||
| !isEmptyObject(report) ? report : undefined, | ||||||||||||
| currentUserAccountID, | ||||||||||||
| chatReport, | ||||||||||||
| { | ||||||||||||
| showChatPreviewLine: false, | ||||||||||||
| forcePolicyNamePreview: false, | ||||||||||||
|
|
@@ -1176,7 +1169,6 @@ | |||||||||||
| currentUserAccountID: number, | ||||||||||||
| personalDetails: OnyxEntry<PersonalDetailsList>, | ||||||||||||
| privateIsArchived: string | undefined, | ||||||||||||
| chatReport: OnyxEntry<Report>, | ||||||||||||
| reportAttributesDerived?: ReportAttributesDerivedValue['reports'], | ||||||||||||
| visibleReportActionsData: VisibleReportActionsDerivedValue = {}, | ||||||||||||
| ): OptionData { | ||||||||||||
|
|
@@ -1187,7 +1179,6 @@ | |||||||||||
| personalDetails ?? {}, | ||||||||||||
| !isEmptyObject(report) ? report : undefined, | ||||||||||||
| currentUserAccountID, | ||||||||||||
| chatReport, | ||||||||||||
| { | ||||||||||||
| showChatPreviewLine: false, | ||||||||||||
| forcePolicyNamePreview: false, | ||||||||||||
|
|
@@ -1229,7 +1220,6 @@ | |||||||||||
| currentUserAccountID: number, | ||||||||||||
| personalDetails: OnyxEntry<PersonalDetailsList>, | ||||||||||||
| expenseReport: OnyxEntry<Report>, | ||||||||||||
| chatReport: OnyxEntry<Report>, | ||||||||||||
| reportAttributesDerived?: ReportAttributesDerivedValue['reports'], | ||||||||||||
| visibleReportActionsData: VisibleReportActionsDerivedValue = {}, | ||||||||||||
| ): SearchOptionData { | ||||||||||||
|
|
@@ -1242,7 +1232,6 @@ | |||||||||||
| personalDetails ?? {}, | ||||||||||||
| !isEmptyObject(expenseReport) ? expenseReport : null, | ||||||||||||
| currentUserAccountID, | ||||||||||||
| chatReport, | ||||||||||||
| { | ||||||||||||
| showChatPreviewLine: false, | ||||||||||||
| forcePolicyNamePreview: false, | ||||||||||||
|
|
@@ -1360,7 +1349,6 @@ | |||||||||||
| personalDetails: OnyxEntry<PersonalDetailsList>, | ||||||||||||
| privateIsArchived: string | undefined, | ||||||||||||
| currentUserAccountID: number, | ||||||||||||
| chatReport: OnyxEntry<Report>, | ||||||||||||
| reportAttributesDerived?: ReportAttributesDerivedValue['reports'], | ||||||||||||
| visibleReportActionsData: VisibleReportActionsDerivedValue = {}, | ||||||||||||
| ): { | ||||||||||||
|
|
@@ -1386,7 +1374,7 @@ | |||||||||||
| reportMapEntry, | ||||||||||||
| reportOption: { | ||||||||||||
| item: report, | ||||||||||||
| ...createOption(accountIDs, personalDetails, report, currentUserAccountID, chatReport, undefined, reportAttributesDerived, privateIsArchived, visibleReportActionsData), | ||||||||||||
| ...createOption(accountIDs, personalDetails, report, currentUserAccountID, undefined, reportAttributesDerived, privateIsArchived, visibleReportActionsData), | ||||||||||||
| }, | ||||||||||||
| }; | ||||||||||||
| } | ||||||||||||
|
|
@@ -1407,16 +1395,7 @@ | |||||||||||
| if (reports) { | ||||||||||||
| for (const report of Object.values(reports)) { | ||||||||||||
| const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]; | ||||||||||||
| const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; | ||||||||||||
| const {reportMapEntry, reportOption} = processReport( | ||||||||||||
| report, | ||||||||||||
| personalDetails, | ||||||||||||
| privateIsArchived, | ||||||||||||
| currentUserAccountID, | ||||||||||||
| chatReport, | ||||||||||||
| reportAttributesDerived, | ||||||||||||
| visibleReportActionsData, | ||||||||||||
| ); | ||||||||||||
| const {reportMapEntry, reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, reportAttributesDerived, visibleReportActionsData); | ||||||||||||
|
|
||||||||||||
| if (reportMapEntry) { | ||||||||||||
| const [accountID, reportValue] = reportMapEntry; | ||||||||||||
|
|
@@ -1432,16 +1411,13 @@ | |||||||||||
| const allPersonalDetailsOptions = Object.values(personalDetails ?? {}).map((personalDetail) => { | ||||||||||||
| const report = reportMapForAccountIDs[personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID]; | ||||||||||||
| const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]; | ||||||||||||
| const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; | ||||||||||||
|
|
||||||||||||
| return { | ||||||||||||
| item: personalDetail, | ||||||||||||
| ...createOption( | ||||||||||||
| [personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID], | ||||||||||||
| personalDetails, | ||||||||||||
| report, | ||||||||||||
| currentUserAccountID, | ||||||||||||
| chatReport, | ||||||||||||
| { | ||||||||||||
| showPersonalDetails: true, | ||||||||||||
| }, | ||||||||||||
|
|
@@ -1540,8 +1516,7 @@ | |||||||||||
| const reportOptions: Array<SearchOption<Report>> = []; | ||||||||||||
| for (const report of limitedReports) { | ||||||||||||
| const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]; | ||||||||||||
| const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; | ||||||||||||
| const {reportMapEntry, reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, chatReport, reportAttributesDerived, visibleReportActionsData); | ||||||||||||
| const {reportMapEntry, reportOption} = processReport(report, personalDetails, privateIsArchived, currentUserAccountID, reportAttributesDerived, visibleReportActionsData); | ||||||||||||
|
|
||||||||||||
| if (reportMapEntry) { | ||||||||||||
| const [accountID, reportValue] = reportMapEntry; | ||||||||||||
|
|
@@ -1571,15 +1546,13 @@ | |||||||||||
|
|
||||||||||||
| const report = reportMapForAccountIDs[accountID]; | ||||||||||||
| const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]; | ||||||||||||
| const chatReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; | ||||||||||||
| return { | ||||||||||||
| item: personalDetail, | ||||||||||||
| ...createOption( | ||||||||||||
| [accountID], | ||||||||||||
| personalDetails, | ||||||||||||
| reportMapForAccountIDs[accountID], | ||||||||||||
| currentUserAccountID, | ||||||||||||
| chatReport, | ||||||||||||
| {showPersonalDetails: true}, | ||||||||||||
| reportAttributesDerived, | ||||||||||||
| privateIsArchived, | ||||||||||||
|
|
@@ -1599,7 +1572,6 @@ | |||||||||||
| report: Report, | ||||||||||||
| personalDetails: OnyxEntry<PersonalDetailsList>, | ||||||||||||
| currentUserAccountID: number, | ||||||||||||
| chatReport: OnyxEntry<Report>, | ||||||||||||
| privateIsArchived: string | undefined, | ||||||||||||
| reportAttributesDerived?: ReportAttributesDerivedValue['reports'], | ||||||||||||
| config?: PreviewConfig, | ||||||||||||
|
|
@@ -1609,7 +1581,7 @@ | |||||||||||
|
|
||||||||||||
| return { | ||||||||||||
| item: report, | ||||||||||||
| ...createOption(accountIDs, personalDetails, report, currentUserAccountID, chatReport, config, reportAttributesDerived, privateIsArchived, visibleReportActionsData), | ||||||||||||
| ...createOption(accountIDs, personalDetails, report, currentUserAccountID, config, reportAttributesDerived, privateIsArchived, visibleReportActionsData), | ||||||||||||
| }; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
@@ -1933,17 +1905,7 @@ | |||||||||||
| login: searchValue, | ||||||||||||
| }, | ||||||||||||
| }; | ||||||||||||
| const userToInvite = createOption( | ||||||||||||
| [optimisticAccountID], | ||||||||||||
| personalDetailsExtended, | ||||||||||||
| null, | ||||||||||||
| currentUserAccountID, | ||||||||||||
| undefined, | ||||||||||||
| {showChatPreviewLine}, | ||||||||||||
| undefined, | ||||||||||||
| undefined, | ||||||||||||
| visibleReportActionsData, | ||||||||||||
| ); | ||||||||||||
| const userToInvite = createOption([optimisticAccountID], personalDetailsExtended, null, currentUserAccountID, {showChatPreviewLine}, undefined, undefined, visibleReportActionsData); | ||||||||||||
| userToInvite.isOptimisticAccount = true; | ||||||||||||
| userToInvite.login = searchValue; | ||||||||||||
|
|
||||||||||||
|
|
@@ -2934,9 +2896,8 @@ | |||||||||||
| if (isReportPolicyExpenseChat) { | ||||||||||||
| // TODO: This allReports usage is temporary and will be removed once the full Onyx.connect() refactor is complete (https://github.com/Expensify/App/issues/66378) | ||||||||||||
| const expenseReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`]; | ||||||||||||
| const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${expenseReport?.chatReportID}`]; | ||||||||||||
| const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport?.reportID}`]; | ||||||||||||
| return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, chatReport, reportAttributesDerived); | ||||||||||||
| return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, reportAttributesDerived); | ||||||||||||
| } | ||||||||||||
| return getParticipantsOption(participant, personalDetails); | ||||||||||||
| }) | ||||||||||||
|
|
@@ -2967,9 +2928,8 @@ | |||||||||||
| if (isReportPolicyExpenseChat) { | ||||||||||||
| // TODO: This allReports usage is temporary and will be removed once the full Onyx.connect() refactor is complete (https://github.com/Expensify/App/issues/66378) | ||||||||||||
| const expenseReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`]; | ||||||||||||
| const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${expenseReport?.chatReportID}`]; | ||||||||||||
| const privateIsArchived = privateIsArchivedMap[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport?.reportID}`]; | ||||||||||||
| return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, chatReport, reportAttributesDerived); | ||||||||||||
| return getPolicyExpenseReportOption(participant, privateIsArchived, currentUserAccountID, personalDetails, expenseReport, reportAttributesDerived); | ||||||||||||
| } | ||||||||||||
| return getParticipantsOption(participant, personalDetails); | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getLastMessageTextForReport()now relies exclusively oncachedOneTransactionThreadReportIDs, but that cache is only populated inside theREPORT_ACTIONSsubscription. Ifreport/chatReportis unavailable when that callback runs (or ifchatReportIDis updated later), the cached value staysundefinedand we stop including transaction-thread actions in preview generation for one-transaction reports, so LHN/search previews can show stale parent-report text until another report-action update happens.Useful? React with 👍 / 👎.