Skip to content

Commit

Permalink
Merge pull request #43463 from Expensify/dsilva_addClientUpdateIDOnWr…
Browse files Browse the repository at this point in the history
…iteRequests

[No QA] Add client updateID on write requests
  • Loading branch information
danieldoglas authored Jun 11, 2024
2 parents 6eea419 + 6eb672a commit fb276f4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libs/API/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 ONYXKEYS from '@src/ONYXKEYS';
import type OnyxRequest from '@src/types/onyx/Request';
import type Response from '@src/types/onyx/Response';
import pkg from '../../../package.json';
Expand Down Expand Up @@ -39,6 +40,14 @@ type OnyxData = {
finallyData?: OnyxUpdate[];
};

// For all write requests, we'll send the lastUpdateID that is applied to this client. This will
// allow us to calculate previousUpdateID faster.
let lastUpdateIDAppliedToClient = 0;
Onyx.connect({
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
callback: (value) => (lastUpdateIDAppliedToClient = value ?? 0),
});

/**
* All calls to API.write() will be persisted to disk as JSON with the params, successData, and failureData (or finallyData, if included in place of the former two values).
* This is so that if the network is unavailable or the app is closed, we can send the WRITE request later.
Expand Down Expand Up @@ -82,6 +91,7 @@ function write<TCommand extends WriteCommand>(command: TCommand, apiCommandParam
// This should be removed once we are no longer using deprecatedAPI https://github.com/Expensify/Expensify/issues/215650
shouldRetry: true,
canCancel: true,
clientUpdateID: lastUpdateIDAppliedToClient,
},
...onyxDataWithoutOptimisticData,
};
Expand Down Expand Up @@ -130,6 +140,7 @@ function makeRequestWithSideEffects<TCommand extends SideEffectRequestCommand |
...apiCommandParameters,
appversion: pkg.version,
apiRequestType,
clientUpdateID: lastUpdateIDAppliedToClient,
};

// Assemble all the request data we'll be storing
Expand Down

0 comments on commit fb276f4

Please sign in to comment.