@onehat/data 1.13.3 → 1.13.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.13.3",
3
+ "version": "1.13.4",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -68,26 +68,35 @@ class AsyncStorageRepository extends OfflineRepository {
68
68
  console.log(this.name, 'AsyncStorage.multiGet results', keys, results);
69
69
  }
70
70
 
71
- let values = [];
71
+ const values = [];
72
72
  if (!_.isNil(results)) {
73
- _.each(results, ([key, value]) => {
74
- let parsed;
75
- try {
76
- parsed = JSON.parse(value);
77
- } catch (e) {
78
- parsed = value; // Invalid JSON, just return raw result
73
+ const chunks = _.chunk(results, 400); // create chunks of 400, which we'll iterate through, so we don't get "Excessive number of pending callbacks" error
74
+ let i, n, thisChunk, promises, promise, parsed;
75
+ for (i = 0; i < chunks.length; i++) { // iterate the chunks
76
+ thisChunk = chunks[i];
77
+ for (n = 0; n < thisChunk.length; n++) { // iterate the storage items
78
+ let [ key, value ] = thisChunk[n];
79
+
80
+ try {
81
+ parsed = JSON.parse(value);
82
+ } catch (e) {
83
+ parsed = value; // Invalid JSON, just return raw result
84
+ }
85
+ if (parsed === null) {
86
+ // Values should be stored as JSON, so it should be either {} or []. If it's null, that means the AsyncStorage can't find the record
87
+ // Delete the index to this record
88
+ const re = new RegExp('^' + this.name + '\-' + '(.*)'),
89
+ matches = key.match(re);
90
+ const id = parseInt(matches, 10);
91
+ promise = this._deleteFromIndex(id);
92
+ promises.push(promise);
93
+ } else {
94
+ values.push(parsed);
95
+ }
79
96
  }
80
- if (parsed === null) {
81
- // Values should be stored as JSON, so it should be either {} or []. If it's null, that means the AsyncStorage can't find the record
82
- // Delete the index to this record
83
- const re = new RegExp('^' + this.name + '\-' + '(.*)'),
84
- matches = key.match(re);
85
- const id = parseInt(matches, 10);
86
- this._deleteFromIndex(id);
87
- } else {
88
- values.push(parsed);
89
- }
90
- })
97
+
98
+ await Promise.all(promises);
99
+ }
91
100
  }
92
101
 
93
102
  // if (this.debugMode && _.size(keys) < 20) {