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

Save queued updates to memory only #25614

Merged
merged 10 commits into from
Sep 28, 2023
4 changes: 0 additions & 4 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ const ONYXKEYS = {
/** Note: These are Persisted Requests - not all requests in the main queue as the key name might lead one to believe */
PERSISTED_REQUESTS: 'networkRequestQueue',

/** Onyx updates from a response, or success or failure data from a request. */
QUEUED_ONYX_UPDATES: 'queuedOnyxUpdates',

/** Stores current date */
CURRENT_DATE: 'currentDate',

Expand Down Expand Up @@ -309,7 +306,6 @@ type OnyxValues = {
[ONYXKEYS.IS_SIDEBAR_LOADED]: boolean;
[ONYXKEYS.SHOW_DOWNLOAD_APP_BANNER]: boolean;
[ONYXKEYS.PERSISTED_REQUESTS]: OnyxTypes.Request[];
[ONYXKEYS.QUEUED_ONYX_UPDATES]: OnyxTypes.QueuedOnyxUpdates;
[ONYXKEYS.CURRENT_DATE]: string;
[ONYXKEYS.CREDENTIALS]: OnyxTypes.Credentials;
[ONYXKEYS.IOU]: OnyxTypes.IOU;
Expand Down
15 changes: 5 additions & 10 deletions src/libs/actions/QueuedOnyxUpdates.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import Onyx from 'react-native-onyx';
import ONYXKEYS from '../../ONYXKEYS';

// In this file we manage a queue of Onyx updates while the SequentialQueue is processing. There are functions to get the updates and clear the queue after saving the updates in Onyx.

// In this file we manage a queue of Onyx updates while the SequentialQueue is processing. There are functions to get the updates and clear the queue after saving the updates.
let queuedOnyxUpdates = [];
Onyx.connect({
key: ONYXKEYS.QUEUED_ONYX_UPDATES,
callback: (val) => (queuedOnyxUpdates = val || []),
});

/**
* @param {Array<Object>} updates Onyx updates to queue for later
* @returns {Promise}
* @returns {Promise<void>}
*/
function queueOnyxUpdates(updates) {
return Onyx.set(ONYXKEYS.QUEUED_ONYX_UPDATES, [...queuedOnyxUpdates, ...updates]);
queuedOnyxUpdates = queuedOnyxUpdates.concat(updates);
return Promise.resolve();
}

function clear() {
Onyx.set(ONYXKEYS.QUEUED_ONYX_UPDATES, null);
queuedOnyxUpdates = [];
}

/**
Expand Down