From 9af0ba1bb8c0f4992ef49d14d2a34fc8a09aaaa9 Mon Sep 17 00:00:00 2001 From: kunkliricsi Date: Sat, 21 Nov 2020 19:42:14 +0100 Subject: [PATCH] Best optimization so far --- .../ClientApp/src/components/dashboard/Dashboard.jsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Birdmap.API/ClientApp/src/components/dashboard/Dashboard.jsx b/Birdmap.API/ClientApp/src/components/dashboard/Dashboard.jsx index 10a6905..f4c5aef 100644 --- a/Birdmap.API/ClientApp/src/components/dashboard/Dashboard.jsx +++ b/Birdmap.API/ClientApp/src/components/dashboard/Dashboard.jsx @@ -51,9 +51,7 @@ class Dashboard extends Component { this.context.addHandler(C.update_all_method_name, this.updateSeries); this.context.addHandler(C.update_method_name, this.updateSeries); this.updateSeries(); - window.setInterval(() => { - this.updateDynamic(); - }, 2000); + this.updateDynamic(); } componentWillUnmount() { @@ -108,11 +106,9 @@ class Dashboard extends Component { deviceSeries: this.getDeviceSeries(), sensorSeries: this.getSensorSeries() }); - - this.updateDynamic(); } - updateDynamic() { + updateDynamic = () => { const secondAgo = new Date(); secondAgo.setMilliseconds(0); const minuteAgo = new Date( Date.now() - 1000 * 60 ); @@ -247,12 +243,14 @@ class Dashboard extends Component { barCategories: getBarCategories(), lineSeries: lineSeries, }); + + setTimeout(this.updateDynamic, 1000); } const processHeatmapItem = processMethod.bind(this); const onFinished = finishMethod.bind(this) - this.performTask(this.context.heatmapPoints, 10, 150, + this.performTask(this.context.heatmapPoints, Math.ceil(this.context.heatmapPoints.length / 100), 10, processHeatmapItem, onFinished); }