Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Onyx from 'react-native-onyx';
import type {DeferredUpdatesDictionary} from '@libs/actions/OnyxUpdateManager/types';
import Log from '@libs/Log';
import * as SequentialQueue from '@libs/Network/SequentialQueue';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -78,6 +79,7 @@ type EnqueueDeferredOnyxUpdatesOptions = {
*/
function enqueue(updates: OnyxUpdatesFromServer | DeferredUpdatesDictionary, options?: EnqueueDeferredOnyxUpdatesOptions) {
if (options?.shouldPauseSequentialQueue ?? true) {
Log.info('[DeferredOnyxUpdates] Pausing SequentialQueue');
SequentialQueue.pause();
}

Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ function subscribeToUserEvents() {
updates: pushEventData.updates ?? [],
previousUpdateID: Number(pushJSON.previousUpdateID ?? CONST.DEFAULT_NUMBER_ID),
};
Log.info('[subscribeToUserEvents] Applying Onyx updates');
applyOnyxUpdatesReliably(updates);
});

Expand Down
10 changes: 6 additions & 4 deletions src/libs/actions/applyOnyxUpdatesReliably.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Log from '@libs/Log';
import * as SequentialQueue from '@libs/Network/SequentialQueue';
import CONST from '@src/CONST';
import type {OnyxUpdatesFromServer} from '@src/types/onyx';
import {handleMissingOnyxUpdates} from './OnyxUpdateManager';
import * as OnyxUpdates from './OnyxUpdates';
import {doesClientNeedToBeUpdated, apply as onyxApply, saveUpdateInformation} from './OnyxUpdates';

type ApplyOnyxUpdatesReliablyOptions = {
clientLastUpdateID?: number;
Expand All @@ -20,6 +21,7 @@ type ApplyOnyxUpdatesReliablyOptions = {
*/
export default function applyOnyxUpdatesReliably(updates: OnyxUpdatesFromServer, {shouldRunSync = false, clientLastUpdateID}: ApplyOnyxUpdatesReliablyOptions = {}) {
const fetchMissingUpdates = () => {
Log.info('[applyOnyxUpdatesReliably] Fetching missing updates');
// If we got here, that means we are missing some updates on our local storage. To
// guarantee that we're not fetching more updates before our local data is up to date,
// let's stop the sequential queue from running until we're done catching up.
Expand All @@ -28,7 +30,7 @@ export default function applyOnyxUpdatesReliably(updates: OnyxUpdatesFromServer,
if (shouldRunSync) {
handleMissingOnyxUpdates(updates, clientLastUpdateID);
} else {
OnyxUpdates.saveUpdateInformation(updates);
saveUpdateInformation(updates);
}
};

Expand All @@ -40,8 +42,8 @@ export default function applyOnyxUpdatesReliably(updates: OnyxUpdatesFromServer,
}

const previousUpdateID = Number(updates.previousUpdateID) ?? CONST.DEFAULT_NUMBER_ID;
if (!OnyxUpdates.doesClientNeedToBeUpdated({previousUpdateID, clientLastUpdateID})) {
OnyxUpdates.apply(updates);
if (!doesClientNeedToBeUpdated({previousUpdateID, clientLastUpdateID})) {
onyxApply(updates);
return;
}

Expand Down