Skip to content

Commit

Permalink
terminate merge queue if set was called
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Pader committed Dec 19, 2023
1 parent bd480d2 commit ea2096d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ function set(key, value) {
}

if (hasPendingMergeForKey(key)) {
Logger.logAlert(`Onyx.set() called after Onyx.merge() for key: ${key}. It is recommended to use set() or merge() not both.`);
delete mergeQueue[key]
}

const hasChanged = cache.hasValueChanged(key, valueWithoutNull);
Expand Down Expand Up @@ -1236,6 +1236,9 @@ function merge(key, changes) {
mergeQueue[key] = [changes];

mergeQueuePromise[key] = get(key).then((existingValue) => {
// Calls to Onyx.set after a merge will terminate the current merge process and clear the merge queue
if (mergeQueue[key] == null) return

try {
// We first only merge the changes, so we can provide these to the native implementation (SQLite uses only delta changes in "JSON_PATCH" to merge)
// We don't want to remove null values from the "batchedChanges", because SQLite uses them to remove keys from storage natively.
Expand Down

0 comments on commit ea2096d

Please sign in to comment.