Skip to content

Commit

Permalink
Merge pull request #40619 from tienifr/fix/40297
Browse files Browse the repository at this point in the history
fix add queue command length log
  • Loading branch information
arosiclair authored Apr 22, 2024
2 parents 98d85e0 + 7fb8b40 commit 68e6630
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/libs/API/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -159,6 +160,9 @@ function read<TCommand extends ReadCommand>(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));
}

Expand Down
11 changes: 9 additions & 2 deletions src/libs/actions/PersistedRequests.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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) {
Expand Down Expand Up @@ -48,4 +55,4 @@ function getAll(): Request[] {
return persistedRequests;
}

export {clear, save, getAll, remove, update};
export {clear, save, getAll, remove, update, getLength};

0 comments on commit 68e6630

Please sign in to comment.