fleetmap-reports 2.0.369 → 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
|
@@ -29,7 +29,7 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
|
29
29
|
|
|
30
30
|
if (isClientSide() && (devices.length > 50 || ((new Date(to).getTime() - new Date(from).getTime()) > (1000 * 60 * 60 * 24 * 15)))) {
|
|
31
31
|
const sliced = automaticReports.sliceArray(devices, 1)
|
|
32
|
-
allData.devices = await executeServerSide('fuel-consumption-report', sliced, from, to, userData, devices.length, traccar,
|
|
32
|
+
allData.devices = await executeServerSide('fuel-consumption-report', sliced, from, to, userData, devices.length, traccar, 10)
|
|
33
33
|
allData.totalDevices = allData.devices.length
|
|
34
34
|
reportData.push(allData)
|
|
35
35
|
return reportData
|
|
@@ -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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
|