diff --git a/src/libs/API/parameters/ReconnectAppParams.ts b/src/libs/API/parameters/ReconnectAppParams.ts index 8c5b7d6c0da9..1deb7aa32eb6 100644 --- a/src/libs/API/parameters/ReconnectAppParams.ts +++ b/src/libs/API/parameters/ReconnectAppParams.ts @@ -1,5 +1,4 @@ type ReconnectAppParams = { - mostRecentReportActionLastModified?: string; updateIDFrom?: number; policyIDList: string[]; }; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 9efe8c1cb014..6bcd4afc9246 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -987,45 +987,6 @@ function getReportAction(reportID: string | undefined, reportActionID: string | return allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]?.[reportActionID]; } -function getMostRecentReportActionLastModified(): string { - // Start with the oldest date possible - let mostRecentReportActionLastModified = DateUtils.getDBTime(0); - - // Flatten all the actions - // Loop over them all to find the one that is the most recent - const flatReportActions = Object.values(allReportActions ?? {}) - .flatMap((actions) => (actions ? Object.values(actions) : [])) - .filter(Boolean); - flatReportActions.forEach((action) => { - // Pending actions should not be counted here as a user could create a comment or some other action while offline and the server might know about - // messages they have not seen yet. - if (action.pendingAction) { - return; - } - - const lastModified = action.lastModified ?? action.created; - - if (lastModified < mostRecentReportActionLastModified) { - return; - } - - mostRecentReportActionLastModified = lastModified; - }); - - // We might not have actions so we also look at the report objects to see if any have a lastVisibleActionLastModified that is more recent. We don't need to get - // any reports that have been updated before either a recently updated report or reportAction as we should be up to date on these - Object.values(allReports ?? {}).forEach((report) => { - const reportLastVisibleActionLastModified = report?.lastVisibleActionLastModified ?? report?.lastVisibleActionCreated; - if (!reportLastVisibleActionLastModified || reportLastVisibleActionLastModified < mostRecentReportActionLastModified) { - return; - } - - mostRecentReportActionLastModified = reportLastVisibleActionLastModified; - }); - - return mostRecentReportActionLastModified; -} - /** * @returns The report preview action or `null` if one couldn't be found */ @@ -2265,7 +2226,6 @@ export { getReportActionMessageFragments, getMessageOfOldDotReportAction, getMostRecentIOURequestActionID, - getMostRecentReportActionLastModified, getNumberOfMoneyRequests, getOneTransactionThreadReportID, getOriginalMessage, diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index f5fa451c59a4..226299c4ad41 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -16,7 +16,6 @@ import Log from '@libs/Log'; import getCurrentUrl from '@libs/Navigation/currentUrl'; import Navigation from '@libs/Navigation/Navigation'; import Performance from '@libs/Performance'; -import {getMostRecentReportActionLastModified} from '@libs/ReportActionsUtils'; import {isLoggingInAsNewUser as isLoggingInAsNewUserSessionUtils} from '@libs/SessionUtils'; import {clearSoundAssetsCache} from '@libs/Sound'; import CONST from '@src/CONST'; @@ -313,15 +312,6 @@ function reconnectApp(updateIDFrom: OnyxEntry = 0) { getPolicyParamsForOpenOrReconnect().then((policyParams) => { const params: ReconnectAppParams = policyParams; - // When the app reconnects we do a fast "sync" of the LHN and only return chats that have new messages. We achieve this by sending the most recent reportActionID. - // we have locally. And then only update the user about chats with messages that have occurred after that reportActionID. - // - // - Look through the local report actions and reports to find the most recently modified report action or report. - // - We send this to the server so that it can compute which new chats the user needs to see and return only those as an optimization. - Timing.start(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION); - params.mostRecentReportActionLastModified = getMostRecentReportActionLastModified(); - Timing.end(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION, '', 500); - // Include the update IDs when reconnecting so that the server can send incremental updates if they are available. // Otherwise, a full set of app data will be returned. if (updateIDFrom) { @@ -345,15 +335,6 @@ function finalReconnectAppAfterActivatingReliableUpdates(): Promise { const params: ReconnectAppParams = {...policyParams}; - // When the app reconnects we do a fast "sync" of the LHN and only return chats that have new messages. We achieve this by sending the most recent reportActionID. - // we have locally. And then only update the user about chats with messages that have occurred after that reportActionID. - // - // - Look through the local report actions and reports to find the most recently modified report action or report. - // - We send this to the server so that it can compute which new chats the user needs to see and return only those as an optimization. - Timing.start(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION); - params.mostRecentReportActionLastModified = getMostRecentReportActionLastModified(); - Timing.end(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION, '', 500); - // It is SUPER BAD FORM to return promises from action methods. // DO NOT FOLLOW THIS PATTERN!!!!! // It was absolutely necessary in order to not break the app while migrating to the new reliable updates pattern. This method will be removed diff --git a/tests/perf-test/ReportActionsUtils.perf-test.ts b/tests/perf-test/ReportActionsUtils.perf-test.ts index b0ebd7c0c10a..601a232abacb 100644 --- a/tests/perf-test/ReportActionsUtils.perf-test.ts +++ b/tests/perf-test/ReportActionsUtils.perf-test.ts @@ -1,6 +1,6 @@ import Onyx from 'react-native-onyx'; import {measureFunction} from 'reassure'; -import * as ReportActionsUtils from '@libs/ReportActionsUtils'; +import {getLastClosedReportAction, getLastVisibleAction, getLastVisibleMessage, getMostRecentIOURequestActionID, getSortedReportActionsForDisplay} from '@libs/ReportActionsUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {ReportActions} from '@src/types/onyx/ReportAction'; @@ -63,7 +63,7 @@ describe('ReportActionsUtils', () => { */ test('[ReportActionsUtils] getLastVisibleAction on 10k reportActions', async () => { await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId)); + await measureFunction(() => getLastVisibleAction(reportId)); }); test('[ReportActionsUtils] getLastVisibleAction on 10k reportActions with actionsToMerge', async () => { @@ -89,19 +89,19 @@ describe('ReportActionsUtils', () => { } as unknown as ReportActions; await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId, true, actionsToMerge)); + await measureFunction(() => getLastVisibleAction(reportId, true, actionsToMerge)); }); test('[ReportActionsUtils] getMostRecentIOURequestActionID on 10k ReportActions', async () => { - const reportActionsArray = ReportActionsUtils.getSortedReportActionsForDisplay(reportActions, true); + const reportActionsArray = getSortedReportActionsForDisplay(reportActions, true); await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getMostRecentIOURequestActionID(reportActionsArray)); + await measureFunction(() => getMostRecentIOURequestActionID(reportActionsArray)); }); test('[ReportActionsUtils] getLastVisibleMessage on 10k ReportActions', async () => { await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getLastVisibleMessage(reportId)); + await measureFunction(() => getLastVisibleMessage(reportId)); }); test('[ReportActionsUtils] getLastVisibleMessage on 10k ReportActions with actionsToMerge', async () => { @@ -127,21 +127,16 @@ describe('ReportActionsUtils', () => { } as unknown as ReportActions; await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getLastVisibleMessage(reportId, true, actionsToMerge)); + await measureFunction(() => getLastVisibleMessage(reportId, true, actionsToMerge)); }); test('[ReportActionsUtils] getSortedReportActionsForDisplay on 10k ReportActions', async () => { await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getSortedReportActionsForDisplay(reportActions, true)); + await measureFunction(() => getSortedReportActionsForDisplay(reportActions, true)); }); test('[ReportActionsUtils] getLastClosedReportAction on 10k ReportActions', async () => { await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getLastClosedReportAction(reportActions)); - }); - - test('[ReportActionsUtils] getMostRecentReportActionLastModified', async () => { - await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getMostRecentReportActionLastModified()); + await measureFunction(() => getLastClosedReportAction(reportActions)); }); });