Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Add client updateID on write requests #43463

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
clientUpdateID: lastUpdateIDAppliedToClient,
lastUpdateID: lastUpdateIDAppliedToClient,

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I prefer clientUpdateID because we already use lastUpdateID in PHP and Auth. Sending it as lastUpdateID would just make things more confusing IMO

},
...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
Loading