diff --git a/src/libs/actions/OnyxUpdateManager/utils/index.ts b/src/libs/actions/OnyxUpdateManager/utils/index.ts index 4df22d292d19..6d51d3ac02a6 100644 --- a/src/libs/actions/OnyxUpdateManager/utils/index.ts +++ b/src/libs/actions/OnyxUpdateManager/utils/index.ts @@ -1,4 +1,5 @@ import Onyx from 'react-native-onyx'; +import Log from '@libs/Log'; import * as App from '@userActions/App'; import type {DeferredUpdatesDictionary, DetectGapAndSplitResult} from '@userActions/OnyxUpdateManager/types'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -76,9 +77,11 @@ function detectGapsAndSplit(updates: DeferredUpdatesDictionary, clientLastUpdate // This function will check for gaps in the deferred updates and // apply the updates in order after the missing updates are fetched and applied -function validateAndApplyDeferredUpdates(clientLastUpdateID?: number): Promise { +function validateAndApplyDeferredUpdates(clientLastUpdateID?: number, previousParams?: {newLastUpdateIDFromClient: number; latestMissingUpdateID: number}): Promise { const lastUpdateIDFromClient = clientLastUpdateID ?? lastUpdateIDAppliedToClient ?? 0; + Log.info('[DeferredUpdates] Processing deferred updates', false, {lastUpdateIDFromClient, previousParams}); + // We only want to apply deferred updates that are newer than the last update that was applied to the client. // At this point, the missing updates from "GetMissingOnyxUpdates" have been applied already, so we can safely filter out. const pendingDeferredUpdates = Object.entries(deferredUpdatesProxy.deferredUpdates).reduce( @@ -100,6 +103,8 @@ function validateAndApplyDeferredUpdates(clientLastUpdateID?: number): Promise { deferredUpdatesProxy.deferredUpdates = {}; @@ -115,15 +120,21 @@ function validateAndApplyDeferredUpdates(clientLastUpdateID?: number): Promise resolve(undefined)) .catch(reject); return; } + // Prevent info loops of calls to GetMissingOnyxMessages + if (previousParams?.newLastUpdateIDFromClient === newLastUpdateIDFromClient && previousParams?.latestMissingUpdateID === latestMissingUpdateID) { + Log.info('[DeferredUpdates] Aborting call to GetMissingOnyxMessages, repeated params', false, {lastUpdateIDFromClient, latestMissingUpdateID, previousParams}); + return; + } + // Then we can fetch the missing updates and apply them App.getMissingOnyxUpdates(newLastUpdateIDFromClient, latestMissingUpdateID) - .then(() => validateAndApplyDeferredUpdates(clientLastUpdateID)) + .then(() => validateAndApplyDeferredUpdates(undefined, {newLastUpdateIDFromClient, latestMissingUpdateID})) .then(() => resolve(undefined)) .catch(reject); });