-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Allow priority requests to go to the front of the sequential queue #23669
Changes from 27 commits
e6ab4fa
4149570
8bff72f
dab8582
297c792
1abb3ff
276ad1e
38a5261
4b25d33
0d1f2a7
0708d43
b9c2781
c15730d
f89a71e
9cc2132
338618d
fb3ba07
b853201
2bd30e8
35bb482
09c7327
f17e3f3
021e41b
d77564c
6a25f77
2eb7c87
7934f37
636f26c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,10 +182,9 @@ function openApp() { | |
/** | ||
* Fetches data when the app reconnects to the network | ||
* @param {Number} [updateIDFrom] the ID of the Onyx update that we want to start fetching from | ||
* @param {Number} [updateIDTo] the ID of the Onyx update that we want to fetch up to | ||
*/ | ||
function reconnectApp(updateIDFrom = 0, updateIDTo = 0) { | ||
console.debug(`[OnyxUpdates] App reconnecting with updateIDFrom: ${updateIDFrom} and updateIDTo: ${updateIDTo}`); | ||
function reconnectApp(updateIDFrom = 0) { | ||
console.debug(`[OnyxUpdates] App reconnecting with updateIDFrom: ${updateIDFrom}`); | ||
getPolicyParamsForOpenOrReconnect().then((policyParams) => { | ||
const params = {...policyParams}; | ||
|
||
|
@@ -204,14 +203,72 @@ function reconnectApp(updateIDFrom = 0, updateIDTo = 0) { | |
params.updateIDFrom = updateIDFrom; | ||
} | ||
|
||
if (updateIDTo) { | ||
params.updateIDTo = updateIDTo; | ||
} | ||
|
||
API.write('ReconnectApp', params, getOnyxDataForOpenOrReconnect()); | ||
}); | ||
} | ||
|
||
/** | ||
* Fetches data when the client has discovered it missed some Onyx updates from the server | ||
* @param {Number} [updateIDFrom] the ID of the Onyx update that we want to start fetching from | ||
* @param {Number} [updateIDTo] the ID of the Onyx update that we want to fetch up to | ||
*/ | ||
function getMissingOnyxUpdates(updateIDFrom = 0, updateIDTo = 0) { | ||
console.debug(`[OnyxUpdates] Fetching missing updates updateIDFrom: ${updateIDFrom} and updateIDTo: ${updateIDTo}`); | ||
|
||
API.write( | ||
'GetMissingOnyxMessages', | ||
{ | ||
updateIDFrom, | ||
updateIDTo, | ||
}, | ||
getOnyxDataForOpenOrReconnect(), | ||
|
||
// Set this to true so that the request will be prioritized at the front of the sequential queue | ||
true, | ||
); | ||
} | ||
|
||
// The next 40ish lines of code are used for detecting when there is a gap of OnyxUpdates between what was last applied to the client and the updates the server has. | ||
// When a gap is detected, the missing updates are fetched from the API. | ||
|
||
// These key needs to be separate from ONYXKEYS.ONYX_UPDATES so that it can be updated without triggering the callback when the server IDs are updated | ||
let lastUpdateIDAppliedToClient = 0; | ||
Onyx.connect({ | ||
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, | ||
callback: (val) => (lastUpdateIDAppliedToClient = val), | ||
}); | ||
|
||
Onyx.connect({ | ||
key: ONYXKEYS.ONYX_UPDATES, | ||
callback: (val) => { | ||
if (!val) { | ||
return; | ||
} | ||
|
||
const {lastUpdateIDFromServer, previousUpdateIDFromServer} = val; | ||
console.debug('[OnyxUpdates] Received lastUpdateID from server', lastUpdateIDFromServer); | ||
console.debug('[OnyxUpdates] Received previousUpdateID from server', previousUpdateIDFromServer); | ||
console.debug('[OnyxUpdates] Last update ID applied to the client', lastUpdateIDAppliedToClient); | ||
|
||
// If the previous update from the server does not match the last update the client got, then the client is missing some updates. | ||
// getMissingOnyxUpdates will fetch updates starting from the last update this client got and going to the last update the server sent. | ||
if (lastUpdateIDAppliedToClient && previousUpdateIDFromServer && lastUpdateIDAppliedToClient < previousUpdateIDFromServer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if expensify goes to mars and beyond, we mayy have more than and then they'll stop getting any updates. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If that's the case, I'll happily come back here and update the logic 😄 |
||
console.debug('[OnyxUpdates] Gap detected in update IDs so fetching incremental updates'); | ||
Log.info('Gap detected in update IDs from server so fetching incremental updates', true, { | ||
lastUpdateIDFromServer, | ||
previousUpdateIDFromServer, | ||
lastUpdateIDAppliedToClient, | ||
}); | ||
getMissingOnyxUpdates(lastUpdateIDAppliedToClient, lastUpdateIDFromServer); | ||
} | ||
|
||
if (lastUpdateIDFromServer > lastUpdateIDAppliedToClient) { | ||
// Update this value so that it matches what was just received from the server | ||
Onyx.merge(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, lastUpdateIDFromServer || 0); | ||
} | ||
}, | ||
}); | ||
|
||
/** | ||
* This promise is used so that deeplink component know when a transition is end. | ||
* This is necessary because we want to begin deeplink redirection after the transition is end. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
|
||
/** | ||
* | ||
* @param {Number} [lastUpdateID] | ||
* @param {Number} [previousUpdateID] | ||
*/ | ||
function saveUpdateIDs(lastUpdateID = 0, previousUpdateID = 0) { | ||
// Return early if there were no updateIDs | ||
if (!lastUpdateID) { | ||
return; | ||
} | ||
|
||
Onyx.merge(ONYXKEYS.ONYX_UPDATES, { | ||
lastUpdateIDFromServer: lastUpdateID, | ||
previousUpdateIDFromServer: previousUpdateID, | ||
}); | ||
} | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export {saveUpdateIDs}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB: These are server updates only. I would have named them
ONYX_SERVER_UPDATES
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated branch and renamed this to
ONYX_UPDATES_FROM_SERVER
following your suggestion (I think the name matches the other key better).