From aa69f3836123d4645ee03acf3089160260a7c3e0 Mon Sep 17 00:00:00 2001 From: Github Date: Thu, 25 Jul 2024 15:00:03 +0200 Subject: [PATCH 1/2] fix: improve getOneTransactionThreadReportID performance --- src/libs/ReportActionsUtils.ts | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index c9e913fae11b..4a6b6753ee16 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -966,28 +966,31 @@ function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEn return; } - const reportActionsArray = Object.values(reportActions ?? {}); + const reportActionsArray = Array.isArray(reportActions) ? reportActions : Object.values(reportActions ?? {}); if (!reportActionsArray.length) { return; } // Get all IOU report actions for the report. - const iouRequestTypes: Array> = [ + const iouRequestTypes = new Set>([ CONST.IOU.REPORT_ACTION_TYPE.CREATE, CONST.IOU.REPORT_ACTION_TYPE.SPLIT, CONST.IOU.REPORT_ACTION_TYPE.PAY, CONST.IOU.REPORT_ACTION_TYPE.TRACK, - ]; + ]); - const iouRequestActions = reportActionsArray.filter((action) => { + const iouRequestActions = []; + for (const action of reportActionsArray) { if (!isMoneyRequestAction(action)) { - return false; + // eslint-disable-next-line no-continue + continue; } + const originalMessage = getOriginalMessage(action); const actionType = originalMessage?.type; - return ( + if ( actionType && - (iouRequestTypes.includes(actionType) ?? []) && + iouRequestTypes.has(actionType) && action.childReportID && // Include deleted IOU reportActions if: // - they have an assocaited IOU transaction ID or @@ -997,22 +1000,27 @@ function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEn // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (isMessageDeleted(action) && action.childVisibleActionCount) || (action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && (isOffline ?? isNetworkOffline))) - ); - }); + ) { + iouRequestActions.push(action); + } + } // If we don't have any IOU request actions, or we have more than one IOU request actions, this isn't a oneTransaction report if (!iouRequestActions.length || iouRequestActions.length > 1) { return; } + const singleAction = iouRequestActions[0]; + const originalMessage = getOriginalMessage(singleAction); + // If there's only one IOU request action associated with the report but it's been deleted, then we don't consider this a oneTransaction report // and want to display it using the standard view - if (isMoneyRequestAction(iouRequestActions[0]) && (getOriginalMessage(iouRequestActions[0])?.deleted ?? '') !== '') { + if (isMoneyRequestAction(singleAction) && (originalMessage?.deleted ?? '') !== '') { return; } // Ensure we have a childReportID associated with the IOU report action - return iouRequestActions[0].childReportID; + return singleAction.childReportID; } /** From 94b83c468a772cccaa8a90ca811e39bbaa4c6953 Mon Sep 17 00:00:00 2001 From: Github Date: Thu, 25 Jul 2024 16:42:30 +0200 Subject: [PATCH 2/2] changes after cr --- src/libs/ReportActionsUtils.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 4a6b6753ee16..50ee4175723c 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -955,6 +955,13 @@ function isTaskAction(reportAction: OnyxEntry): boolean { ); } +// Get all IOU report actions for the report. +const iouRequestTypes = new Set>([ + CONST.IOU.REPORT_ACTION_TYPE.CREATE, + CONST.IOU.REPORT_ACTION_TYPE.SPLIT, + CONST.IOU.REPORT_ACTION_TYPE.PAY, + CONST.IOU.REPORT_ACTION_TYPE.TRACK, +]); /** * Gets the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions. * Returns a reportID if there is exactly one transaction thread for the report, and null otherwise. @@ -971,14 +978,6 @@ function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEn return; } - // Get all IOU report actions for the report. - const iouRequestTypes = new Set>([ - CONST.IOU.REPORT_ACTION_TYPE.CREATE, - CONST.IOU.REPORT_ACTION_TYPE.SPLIT, - CONST.IOU.REPORT_ACTION_TYPE.PAY, - CONST.IOU.REPORT_ACTION_TYPE.TRACK, - ]); - const iouRequestActions = []; for (const action of reportActionsArray) { if (!isMoneyRequestAction(action)) { @@ -1015,7 +1014,7 @@ function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEn // If there's only one IOU request action associated with the report but it's been deleted, then we don't consider this a oneTransaction report // and want to display it using the standard view - if (isMoneyRequestAction(singleAction) && (originalMessage?.deleted ?? '') !== '') { + if ((originalMessage?.deleted ?? '') !== '' && isMoneyRequestAction(singleAction)) { return; }