1
1
import Onyx from 'react-native-onyx' ;
2
+ import Log from '@libs/Log' ;
2
3
import * as App from '@userActions/App' ;
3
4
import type { DeferredUpdatesDictionary , DetectGapAndSplitResult } from '@userActions/OnyxUpdateManager/types' ;
4
5
import ONYXKEYS from '@src/ONYXKEYS' ;
@@ -76,9 +77,11 @@ function detectGapsAndSplit(updates: DeferredUpdatesDictionary, clientLastUpdate
76
77
77
78
// This function will check for gaps in the deferred updates and
78
79
// apply the updates in order after the missing updates are fetched and applied
79
- function validateAndApplyDeferredUpdates ( clientLastUpdateID ?: number ) : Promise < void > {
80
+ function validateAndApplyDeferredUpdates ( clientLastUpdateID ?: number , previousParams ?: { newLastUpdateIDFromClient : number ; latestMissingUpdateID : number } ) : Promise < void > {
80
81
const lastUpdateIDFromClient = clientLastUpdateID ?? lastUpdateIDAppliedToClient ?? 0 ;
81
82
83
+ Log . info ( '[DeferredUpdates] Processing deferred updates' , false , { lastUpdateIDFromClient, previousParams} ) ;
84
+
82
85
// We only want to apply deferred updates that are newer than the last update that was applied to the client.
83
86
// At this point, the missing updates from "GetMissingOnyxUpdates" have been applied already, so we can safely filter out.
84
87
const pendingDeferredUpdates = Object . entries ( deferredUpdatesProxy . deferredUpdates ) . reduce < DeferredUpdatesDictionary > (
@@ -100,6 +103,8 @@ function validateAndApplyDeferredUpdates(clientLastUpdateID?: number): Promise<v
100
103
// If we detected a gap in the deferred updates, only apply the deferred updates before the gap,
101
104
// re-fetch the missing updates and then apply the remaining deferred updates after the gap
102
105
if ( latestMissingUpdateID ) {
106
+ Log . info ( '[DeferredUpdates] Gap detected in deferred updates' , false , { lastUpdateIDFromClient, latestMissingUpdateID} ) ;
107
+
103
108
return new Promise ( ( resolve , reject ) => {
104
109
deferredUpdatesProxy . deferredUpdates = { } ;
105
110
@@ -115,15 +120,21 @@ function validateAndApplyDeferredUpdates(clientLastUpdateID?: number): Promise<v
115
120
116
121
// If lastUpdateIDAppliedToClient got updated in the meantime, we will just retrigger the validation and application of the current deferred updates.
117
122
if ( latestMissingUpdateID <= newLastUpdateIDFromClient ) {
118
- validateAndApplyDeferredUpdates ( clientLastUpdateID )
123
+ validateAndApplyDeferredUpdates ( undefined , { newLastUpdateIDFromClient , latestMissingUpdateID } )
119
124
. then ( ( ) => resolve ( undefined ) )
120
125
. catch ( reject ) ;
121
126
return ;
122
127
}
123
128
129
+ // Prevent info loops of calls to GetMissingOnyxMessages
130
+ if ( previousParams ?. newLastUpdateIDFromClient === newLastUpdateIDFromClient && previousParams ?. latestMissingUpdateID === latestMissingUpdateID ) {
131
+ Log . info ( '[DeferredUpdates] Aborting call to GetMissingOnyxMessages, repeated params' , false , { lastUpdateIDFromClient, latestMissingUpdateID, previousParams} ) ;
132
+ return ;
133
+ }
134
+
124
135
// Then we can fetch the missing updates and apply them
125
136
App . getMissingOnyxUpdates ( newLastUpdateIDFromClient , latestMissingUpdateID )
126
- . then ( ( ) => validateAndApplyDeferredUpdates ( clientLastUpdateID ) )
137
+ . then ( ( ) => validateAndApplyDeferredUpdates ( undefined , { newLastUpdateIDFromClient , latestMissingUpdateID } ) )
127
138
. then ( ( ) => resolve ( undefined ) )
128
139
. catch ( reject ) ;
129
140
} ) ;
0 commit comments