Skip to content

Commit 25cf1cb

Browse files
committed
perf(init): drop redundant setAllKeys() before cache.hydrate()
1 parent 51d14dd commit 25cf1cb

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

lib/Onyx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function init({
109109

110110
// Initialize all of our keys with data provided then give green light to any pending connections.
111111
// addEvictableKeysToRecentlyAccessedList must run after initializeWithDefaultKeyStates because
112-
// eager cache loading populates the key index (cache.setAllKeys) inside initializeWithDefaultKeyStates,
112+
// eager cache loading populates the key index (cache.hydrate) inside initializeWithDefaultKeyStates,
113113
// and the evictable keys list depends on that index being populated.
114114
OnyxUtils.initializeWithDefaultKeyStates()
115115
.then(() => cache.addEvictableKeysToRecentlyAccessedList(OnyxKeys.isCollectionKey, OnyxUtils.getAllKeys))

lib/OnyxUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,8 @@ function initializeWithDefaultKeyStates(): Promise<void> {
10421042
// Load all storage data into cache silently (no subscriber notifications).
10431043
// hydrate() rather than merge(): the cache is empty at this point, so a per-key fastMerge
10441044
// would only deep-clone every row it was handed.
1045-
cache.setAllKeys(Object.keys(allDataFromStorage));
1045+
// No setAllKeys() call is needed: hydrate() calls addKey() for every key, which populates the
1046+
// key index and registers collection member keys itself.
10461047
cache.hydrate(allDataFromStorage);
10471048

10481049
// For keys that have a developer-defined default (via `initialKeyStates`), merge the

0 commit comments

Comments
 (0)