From cb15a800da404ce9e484bcd24564d1fb264fc4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Thu, 1 Aug 2024 22:38:02 +0200 Subject: [PATCH 1/2] getCachedCollection cache --- lib/OnyxUtils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/OnyxUtils.ts b/lib/OnyxUtils.ts index cac8b0b1..528b335b 100644 --- a/lib/OnyxUtils.ts +++ b/lib/OnyxUtils.ts @@ -804,6 +804,9 @@ function keyChanged( return; } } + + const cachedCollections: Record> = {}; + for (let i = 0; i < stateMappingKeys.length; i++) { const subscriber = callbackToStateMapping[stateMappingKeys[i]]; if (!subscriber || !isKeyMatch(subscriber.key, key) || !canUpdateSubscriber(subscriber)) { @@ -820,7 +823,7 @@ function keyChanged( } if (isCollectionKey(subscriber.key) && subscriber.waitForCollectionCallback) { - const cachedCollection = getCachedCollection(subscriber.key); + const cachedCollection = cachedCollections[subscriber.key] ?? getCachedCollection(subscriber.key); cachedCollection[key] = value; subscriber.callback(cachedCollection); From 2f237f9f1a15f36fd33f10cfb9ca4f4f0e446ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 5 Aug 2024 22:24:28 +0200 Subject: [PATCH 2/2] fix getCachedCollection caching --- lib/OnyxUtils.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/OnyxUtils.ts b/lib/OnyxUtils.ts index 528b335b..45961dee 100644 --- a/lib/OnyxUtils.ts +++ b/lib/OnyxUtils.ts @@ -823,7 +823,12 @@ function keyChanged( } if (isCollectionKey(subscriber.key) && subscriber.waitForCollectionCallback) { - const cachedCollection = cachedCollections[subscriber.key] ?? getCachedCollection(subscriber.key); + let cachedCollection = cachedCollections[subscriber.key]; + + if (!cachedCollection) { + cachedCollection = getCachedCollection(subscriber.key); + cachedCollections[subscriber.key] = cachedCollection; + } cachedCollection[key] = value; subscriber.callback(cachedCollection);