fleetmap-reports 2.0.371 → 2.0.372
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 +1 -1
- package/src/util/utils.js +13 -4
package/package.json
CHANGED
package/src/util/utils.js
CHANGED
|
@@ -274,9 +274,15 @@ async function executeServerSide (type, sliced, from, to, userData, totalItems,
|
|
|
274
274
|
console.log('PROGRESS_PERC:1')
|
|
275
275
|
const cookie = await axios.get('/pinmeapi/cookie/get', { withCredentials: true }).then(d => d.data)
|
|
276
276
|
const reportData = []
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
277
|
+
let nextIndex = 0
|
|
278
|
+
|
|
279
|
+
// A worker pool, not fixed-size Promise.all batches: with batches, one slow item (e.g. a device
|
|
280
|
+
// with way more data than its peers) stalls the *entire* next batch behind it, since Promise.all
|
|
281
|
+
// waits for every item before starting the next round. Here, as soon as any worker finishes an
|
|
282
|
+
// item it immediately grabs the next one, so a slow item only delays itself.
|
|
283
|
+
async function worker () {
|
|
284
|
+
while (nextIndex < sliced.length) {
|
|
285
|
+
const items = sliced[nextIndex++]
|
|
280
286
|
const url = `https://${getServerHost()}/pinmeapi/reports/${type}`
|
|
281
287
|
try {
|
|
282
288
|
await axios.post(url, {
|
|
@@ -309,9 +315,12 @@ async function executeServerSide (type, sliced, from, to, userData, totalItems,
|
|
|
309
315
|
console.log('LOADING_MESSAGE:' + items[0].name)
|
|
310
316
|
}
|
|
311
317
|
console.log(`PROGRESS_PERC:${itemsCount / totalItems * 100}`)
|
|
312
|
-
}
|
|
318
|
+
}
|
|
313
319
|
}
|
|
314
320
|
|
|
321
|
+
const workerCount = Math.min(maxRequests, sliced.length)
|
|
322
|
+
await Promise.all(Array.from({ length: workerCount }, () => worker()))
|
|
323
|
+
|
|
315
324
|
if (userData.byDriver) {
|
|
316
325
|
reportData.sort((a, b) => (((a.driver && a.driver.name) || a.name || '') > ((b.driver && b.driver.name) || b.name || '')) ? 1 : -1)
|
|
317
326
|
} else {
|