Skip to content

Commit

Permalink
Merge pull request #40183 from Expensify/revert-40169-dsilva_unpauseQ…
Browse files Browse the repository at this point in the history
…ueueIfAPusherUpdateWasReceivedWhileLoadingOpenApp

Revert "Unpausing the queue when we receive Pusher updates while we're still loading the App"
  • Loading branch information
danieldoglas authored Apr 12, 2024
2 parents 5116f83 + 4ee6a2c commit 723d11d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
22 changes: 10 additions & 12 deletions src/libs/actions/OnyxUpdateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,11 @@ export default () => {
Onyx.connect({
key: ONYXKEYS.ONYX_UPDATES_FROM_SERVER,
callback: (value) => {
// When there's no value, there's nothing to process, so let's return early.
if (!value) {
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.`);
// When the OpenApp command hasn't finished yet, we should not process any updates.
if (!value || isLoadingApp) {
if (isLoadingApp) {
console.debug(`[OnyxUpdateManager] Ignoring Onyx updates while OpenApp hans't finished yet.`);
}
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 @@ -87,6 +80,11 @@ export default () => {
// 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
6 changes: 3 additions & 3 deletions src/libs/actions/OnyxUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ function apply({lastUpdateID, type, request, response, updates}: OnyxUpdatesFrom
* @param [updateParams.updates] Exists if updateParams.type === 'pusher'
*/
function saveUpdateInformation(updateParams: OnyxUpdatesFromServer) {
// Unpause the Sequential queue so we go back to processing requests to guarantee we don't make the app unusable
SequentialQueue.unpause();

// Always use set() here so that the updateParams are never merged and always unique to the request that came in
Onyx.set(ONYXKEYS.ONYX_UPDATES_FROM_SERVER, updateParams);
}
Expand Down Expand Up @@ -151,6 +148,9 @@ function applyOnyxUpdatesReliably(updates: OnyxUpdatesFromServer) {
apply(updates);
return;
}

// If we reached this point, we need to pause the queue while we prepare to fetch older OnyxUpdates.
SequentialQueue.pause();
saveUpdateInformation(updates);
}

Expand Down

0 comments on commit 723d11d

Please sign in to comment.