react-native-onyx 1.0.90 → 1.0.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/Onyx.js CHANGED
@@ -802,7 +802,19 @@ function connect(mapping) {
802
802
  // Commit connection only after init passes
803
803
  deferredInitTask.promise
804
804
  .then(() => addKeyToRecentlyAccessedIfNeeded(mapping))
805
- .then(getAllKeys)
805
+ .then(() => {
806
+ // Performance improvement
807
+ // If the mapping is connected to an onyx key that is not a collection
808
+ // we can skip the call to getAllKeys() and return an array with a single item
809
+ if (Boolean(mapping.key)
810
+ && typeof mapping.key === 'string'
811
+ && !(mapping.key.endsWith('_'))
812
+ && cache.storageKeys.has(mapping.key)
813
+ ) {
814
+ return [mapping.key];
815
+ }
816
+ return getAllKeys();
817
+ })
806
818
  .then((keys) => {
807
819
  // We search all the keys in storage to see if any are a "match" for the subscriber we are connecting so that we
808
820
  // can send data back to the subscriber. Note that multiple keys can match as a subscriber could either be
package/lib/OnyxCache.js CHANGED
@@ -179,12 +179,21 @@ class OnyxCache {
179
179
  * Remove keys that don't fall into the range of recently used keys
180
180
  */
181
181
  removeLeastRecentlyUsedKeys() {
182
- while (this.recentKeys.size > this.maxRecentKeysSize) {
183
- const iterator = this.recentKeys.values();
182
+ let numKeysToRemove = this.recentKeys.size - this.maxRecentKeysSize;
183
+ if (numKeysToRemove <= 0) {
184
+ return;
185
+ }
186
+ const iterator = this.recentKeys.values();
187
+ const temp = [];
188
+ while (numKeysToRemove > 0) {
184
189
  const value = iterator.next().value;
185
- if (value !== undefined) {
186
- this.drop(value);
187
- }
190
+ temp.push(value);
191
+ numKeysToRemove--;
192
+ }
193
+
194
+ for (let i = 0; i < temp.length; ++i) {
195
+ delete this.storageMap[temp[i]];
196
+ this.recentKeys.delete(temp[i]);
188
197
  }
189
198
  }
190
199
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "1.0.90",
3
+ "version": "1.0.92",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",