Skip to content

Commit

Permalink
getCachedCollection cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kacper-mikolajczak committed Aug 1, 2024
1 parent b2e5384 commit cb15a80
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/OnyxUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,9 @@ function keyChanged<TKey extends OnyxKey>(
return;
}
}

const cachedCollections: Record<string, ReturnType<typeof getCachedCollection>> = {};

for (let i = 0; i < stateMappingKeys.length; i++) {
const subscriber = callbackToStateMapping[stateMappingKeys[i]];
if (!subscriber || !isKeyMatch(subscriber.key, key) || !canUpdateSubscriber(subscriber)) {
Expand All @@ -820,7 +823,7 @@ function keyChanged<TKey extends OnyxKey>(
}

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);
Expand Down

0 comments on commit cb15a80

Please sign in to comment.