From 771f4e4f698304c8ca5197a9be1dd53b1de0f505 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Thu, 31 Oct 2019 19:37:36 +0100 Subject: [PATCH] add batching for measurement backfill. --- src/api/workout.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/workout.js b/src/api/workout.js index 83a86a7..6e9c4b4 100644 --- a/src/api/workout.js +++ b/src/api/workout.js @@ -184,7 +184,9 @@ module.exports = function workoutRouter(repo) { } workout.listMeasurements().then((list) => { - ws.send(JSON.stringify({workoutStatusBackfill: list})); + for (let i = 0; i < list.length; i += 240) { + ws.send(JSON.stringify({workoutStatusBackfill: list.slice(i, i+240)})); + } }).catch(err => { ws.send(JSON.stringify({error: `could not list measurements: ${err.message || err}`})); ws.close(); @@ -196,7 +198,7 @@ module.exports = function workoutRouter(repo) { ws.send(JSON.stringify({workotuStatus})) } - + workout.events.on("workoutStatus", handler); ws.onclose = () => {