Skip to content
Prev Previous commit
Merge branch 'main' of github.com:Expensify/App into arosiclair-backg…
…round-missing-updates
  • Loading branch information
arosiclair committed Apr 15, 2024
commit ef8286f38daec6b1d7c8128c1e79204c935c22a3
22 changes: 12 additions & 10 deletions src/libs/actions/OnyxUpdateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,18 @@ Onyx.connect({
* @returns
*/
function handleOnyxUpdateGap(onyxUpdatesFromServer: OnyxEntry<OnyxUpdatesFromServer>, clientLastUpdateID = 0) {
// When the OpenApp command hasn't finished yet, we should not process any updates.
if (!onyxUpdatesFromServer || isLoadingApp) {
if (isLoadingApp) {
console.debug(`[OnyxUpdateManager] Ignoring Onyx updates while OpenApp hans't finished yet.`);
}
// When there's no value, there's nothing to process, so let's return early.
if (!onyxUpdatesFromServer) {
return;
}
// If isLoadingApp is positive it means that OpenApp command hasn't finished yet, and in that case
// we don't have base state of the app (reports, policies, etc) setup. If we apply this update,
// we'll only have them overriten by the openApp response. So let's skip it and return.
if (isLoadingApp) {
// When ONYX_UPDATES_FROM_SERVER is set, we pause the queue. Let's unpause
// it so the app is not stuck forever without processing requests.
SequentialQueue.unpause();
console.debug(`[OnyxUpdateManager] Ignoring Onyx updates while OpenApp hans't finished yet.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*hasn't 🤷

return;
}
// This key is shared across clients, thus every client/tab will have a copy and try to execute this method.
Expand Down Expand Up @@ -85,11 +92,6 @@ function handleOnyxUpdateGap(onyxUpdatesFromServer: OnyxEntry<OnyxUpdatesFromSer
// fully migrating to the reliable updates mode.
// 2. This client already has the reliable updates mode enabled, but it's missing some updates and it
// needs to fetch those.
//
// For both of those, we need to pause the sequential queue. This is important so that the updates are
// applied in their correct and specific order. If this queue was not paused, then there would be a lot of
// onyx data being applied while we are fetching the missing updates and that would put them all out of order.
SequentialQueue.pause();
let canUnpauseQueuePromise;

// The flow below is setting the promise to a reconnect app to address flow (1) explained above.
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/OnyxUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {Merge} from 'type-fest';
import Log from '@libs/Log';
import * as SequentialQueue from '@libs/Network/SequentialQueue';
import PusherUtils from '@libs/PusherUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down
8 changes: 2 additions & 6 deletions src/libs/actions/applyOnyxUpdatesReliably.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as SequentialQueue from '@libs/Network/SequentialQueue';
import type {OnyxUpdatesFromServer} from '@src/types/onyx';
import {handleOnyxUpdateGap} from './OnyxUpdateManager';
import * as OnyxUpdates from './OnyxUpdates';
Expand All @@ -21,10 +20,7 @@ export default function applyOnyxUpdatesReliably(updates: OnyxUpdatesFromServer,

if (shouldRunSync) {
handleOnyxUpdateGap(updates, clientLastUpdateID);
return;
} else {
OnyxUpdates.saveUpdateInformation(updates);
}

// If we reached this point, we need to pause the queue while we prepare to fetch older OnyxUpdates.
SequentialQueue.pause();
OnyxUpdates.saveUpdateInformation(updates);
}
You are viewing a condensed version of this merge commit. You can view the full changes here.