diff --git a/src/libs/API/index.ts b/src/libs/API/index.ts index dbbcf790edf0..bfa1b95836f8 100644 --- a/src/libs/API/index.ts +++ b/src/libs/API/index.ts @@ -5,6 +5,7 @@ import * as Middleware from '@libs/Middleware'; import * as SequentialQueue from '@libs/Network/SequentialQueue'; import * as Pusher from '@libs/Pusher/pusher'; import * as Request from '@libs/Request'; +import * as PersistedRequests from '@userActions/PersistedRequests'; import CONST from '@src/CONST'; import type OnyxRequest from '@src/types/onyx/Request'; import type Response from '@src/types/onyx/Response'; @@ -159,6 +160,9 @@ function read(command: TCommand, apiCommandParamet // Ensure all write requests on the sequential queue have finished responding before running read requests. // Responses from read requests can overwrite the optimistic data inserted by // write requests that use the same Onyx keys and haven't responded yet. + if (PersistedRequests.getLength() > 0) { + Log.info(`[API] '${command}' is waiting on ${PersistedRequests.getLength()} write commands`); + } SequentialQueue.waitForIdle().then(() => makeRequestWithSideEffects(command, apiCommandParameters, onyxData, CONST.API_REQUEST_TYPE.READ)); } diff --git a/src/libs/actions/PersistedRequests.ts b/src/libs/actions/PersistedRequests.ts index 8894af8c374f..839ed5b38763 100644 --- a/src/libs/actions/PersistedRequests.ts +++ b/src/libs/actions/PersistedRequests.ts @@ -1,5 +1,6 @@ import isEqual from 'lodash/isEqual'; import Onyx from 'react-native-onyx'; +import Log from '@libs/Log'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Request} from '@src/types/onyx'; @@ -17,9 +18,15 @@ function clear() { return Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, []); } +function getLength(): number { + return persistedRequests.length; +} + function save(requestToPersist: Request) { persistedRequests.push(requestToPersist); - Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, persistedRequests); + Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, persistedRequests).then(() => { + Log.info(`[SequentialQueue] '${requestToPersist.command}' command queued. Queue length is ${getLength()}`); + }); } function remove(requestToRemove: Request) { @@ -48,4 +55,4 @@ function getAll(): Request[] { return persistedRequests; } -export {clear, save, getAll, remove, update}; +export {clear, save, getAll, remove, update, getLength};