From 4a1d2e4ccc0f72a4066db3a10f67ae7a222eb008 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 30 Aug 2023 10:47:53 -0600 Subject: [PATCH] Revert "Use collection key value map instead of recomputing everytime" --- lib/Onyx.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index 4b210f94..27f49aec 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -27,8 +27,8 @@ let lastConnectionID = 0; // Holds a mapping of all the react components that want their state subscribed to a store key const callbackToStateMapping = {}; -// Keeps a copy of the values of the onyx collection keys as a map for faster lookups -let onyxCollectionKeyMap = {}; +// Stores all of the keys that Onyx can use. Must be defined in init(). +let onyxKeys = {}; // Holds a list of keys that have been directly subscribed to or recently modified from least to most recent let recentlyAccessedKeys = []; @@ -141,7 +141,7 @@ function getAllKeys() { * @returns {Boolean} */ function isCollectionKey(key) { - return onyxCollectionKeyMap.has(key); + return _.contains(_.values(onyxKeys.COLLECTION), key); } /** @@ -1392,13 +1392,8 @@ function init({ cache.setRecentKeysLimit(maxCachedKeysCount); } - // We need the value of the collection keys later for checking if a - // key is a collection. We store it in a map for faster lookup. - const collectionValues = _.values(keys.COLLECTION); - onyxCollectionKeyMap = _.reduce(collectionValues, (acc, val) => { - acc.set(val, true); - return acc; - }, new Map()); + // Let Onyx know about all of our keys + onyxKeys = keys; // Set our default key states to use when initializing and clearing Onyx data defaultKeyStates = initialKeyStates;