From 5d0f71c6f53296b7fc376f7726d556c2296127b0 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 10 Jan 2025 13:07:03 +0100 Subject: [PATCH 1/3] avoid using multiSet for setCollection --- lib/Onyx.ts | 14 +++++++++++++- lib/OnyxUtils.ts | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/Onyx.ts b/lib/Onyx.ts index a15db1d5..77709f0b 100644 --- a/lib/Onyx.ts +++ b/lib/Onyx.ts @@ -767,7 +767,19 @@ function setCollection(coll mutableCollection[key] = null; }); - return multiSet(mutableCollection); + const keyValuePairs = OnyxUtils.prepareKeyValuePairsForStorage(mutableCollection, true); + const previousCollection = OnyxUtils.getCachedCollection(collectionKey); + + keyValuePairs.forEach(([key, value]) => cache.set(key, value)); + + // Single notification for collection subscribers + OnyxUtils.keysChanged(collectionKey, mutableCollection, previousCollection); + + return Storage.multiSet(keyValuePairs) + .catch((error) => OnyxUtils.evictStorageAndRetry(error, setCollection, collectionKey, collection)) + .then(() => { + OnyxUtils.sendActionToDevTools(OnyxUtils.METHOD.SET_COLLECTION, undefined, mutableCollection); + }); }); } diff --git a/lib/OnyxUtils.ts b/lib/OnyxUtils.ts index dcbf839e..8e3de3db 100644 --- a/lib/OnyxUtils.ts +++ b/lib/OnyxUtils.ts @@ -165,13 +165,13 @@ function initStoreValues(keys: DeepRecord, initialKeyStates: Pa * @param mergedValue - (optional) value that was written in the storage after a merge method was executed. */ function sendActionToDevTools( - method: typeof METHOD.MERGE_COLLECTION | typeof METHOD.MULTI_SET, + method: typeof METHOD.MERGE_COLLECTION | typeof METHOD.MULTI_SET | typeof METHOD.SET_COLLECTION, key: undefined, value: OnyxCollection, mergedValue?: undefined, ): void; function sendActionToDevTools( - method: Exclude, + method: Exclude, key: OnyxKey, value: OnyxEntry, mergedValue?: OnyxEntry, From 70ef80d5290e5bcbdc917518a564abf67ae56571 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 10 Jan 2025 13:49:39 +0100 Subject: [PATCH 2/3] use scheduleNotifyCollectionSubscribers --- lib/Onyx.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Onyx.ts b/lib/Onyx.ts index 77709f0b..3d0dc013 100644 --- a/lib/Onyx.ts +++ b/lib/Onyx.ts @@ -772,13 +772,13 @@ function setCollection(coll keyValuePairs.forEach(([key, value]) => cache.set(key, value)); - // Single notification for collection subscribers - OnyxUtils.keysChanged(collectionKey, mutableCollection, previousCollection); + const updatePromise = OnyxUtils.scheduleNotifyCollectionSubscribers(collectionKey, mutableCollection, previousCollection); return Storage.multiSet(keyValuePairs) .catch((error) => OnyxUtils.evictStorageAndRetry(error, setCollection, collectionKey, collection)) .then(() => { OnyxUtils.sendActionToDevTools(OnyxUtils.METHOD.SET_COLLECTION, undefined, mutableCollection); + return updatePromise; }); }); } From c78d7e4f31d881369a8f0e29cc7cb212afda1c02 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 10 Jan 2025 14:01:15 +0100 Subject: [PATCH 3/3] update evictStorageAndRetry --- lib/OnyxUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OnyxUtils.ts b/lib/OnyxUtils.ts index 8e3de3db..15863624 100644 --- a/lib/OnyxUtils.ts +++ b/lib/OnyxUtils.ts @@ -1088,7 +1088,7 @@ function reportStorageQuota(): Promise { * evicting some data from Onyx and then retrying to do * whatever it is we attempted to do. */ -function evictStorageAndRetry( +function evictStorageAndRetry( error: Error, onyxMethod: TMethod, ...args: Parameters