fleetmap-reports 2.0.370 → 2.0.371

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": "fleetmap-reports",
3
- "version": "2.0.370",
3
+ "version": "2.0.371",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -211,11 +211,16 @@ async function runServerSideGrid (from, to, userData, deviceIdsByDriver, traccar
211
211
  const url = `https://${getServerHost()}/pinmeapi/reports/driverranking-report`
212
212
  const rawRows = []
213
213
  let completed = 0
214
- const maxConcurrent = 20
215
-
216
- for (let i = 0; i < cells.length; i += maxConcurrent) {
217
- const batch = cells.slice(i, i + maxConcurrent)
218
- await Promise.all(batch.map(async ({ driverSlice, dateChunk }) => {
214
+ let nextCellIndex = 0
215
+ const maxConcurrent = 10
216
+
217
+ // A worker pool, not fixed-size Promise.all batches: with batches, one slow cell (a device with
218
+ // way more GPS data than its peers) stalls the *entire* next batch behind it, since Promise.all
219
+ // waits for every item before starting the next round. Here, as soon as any worker finishes a
220
+ // cell it immediately grabs the next one, so a slow cell only delays itself.
221
+ async function worker () {
222
+ while (nextCellIndex < cells.length) {
223
+ const { driverSlice, dateChunk } = cells[nextCellIndex++]
219
224
  const deviceIds = new Set()
220
225
  driverSlice.forEach(d => {
221
226
  const ids = deviceIdsByDriver.get(d.uniqueId)
@@ -249,9 +254,12 @@ async function runServerSideGrid (from, to, userData, deviceIdsByDriver, traccar
249
254
  completed++
250
255
  console.log('LOADING_MESSAGE:' + driverSlice[0].name)
251
256
  console.log(`PROGRESS_PERC:${(completed / cells.length) * 100}`)
252
- }))
257
+ }
253
258
  }
254
259
 
260
+ const workerCount = Math.min(maxConcurrent, cells.length)
261
+ await Promise.all(Array.from({ length: workerCount }, () => worker()))
262
+
255
263
  return rawRows
256
264
  }
257
265