@onehat/data 1.13.2 → 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
|
@@ -65,29 +65,38 @@ class AsyncStorageRepository extends OfflineRepository {
|
|
|
65
65
|
const results = await AsyncStorage.multiGet(this._namespace(keys));
|
|
66
66
|
|
|
67
67
|
if (this.debugMode) {
|
|
68
|
-
console.log(this.name, 'AsyncStorage.multiGet results',
|
|
68
|
+
console.log(this.name, 'AsyncStorage.multiGet results', keys, results);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
const values = [];
|
|
72
72
|
if (!_.isNil(results)) {
|
|
73
|
-
_.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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) {
|