From 71b87437c7ce0deb262e7420ebc2531cdac16b26 Mon Sep 17 00:00:00 2001 From: Youen Toupin Date: Sat, 9 Apr 2022 19:51:44 +0200 Subject: [PATCH] disabled mithril redraw for each status request the goal is to allow each page to finely manage how to update with minimum CPU usage --- WebApp/src/monitor-api.ts | 18 ++++++++++++++---- WebApp/src/pages/dashboard/dashboard-page.tsx | 1 + WebApp/src/pages/raw-data/raw-data-page.tsx | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/WebApp/src/monitor-api.ts b/WebApp/src/monitor-api.ts index 3441ded..e3e5c3a 100644 --- a/WebApp/src/monitor-api.ts +++ b/WebApp/src/monitor-api.ts @@ -45,11 +45,21 @@ export class MonitorApi { t: Math.random() * 400 - 100, alt: Math.random() * 4500000 - 200000 } - setTimeout(() => m.redraw(), 0); } else { - apiStatus = await m.request({ - method: "GET", - url: "/api/status" + apiStatus = await new Promise((resolve, error) => { + let request = new XMLHttpRequest(); + request.onreadystatechange = () => { + if(request.readyState == 4) { + if(request.status == 200) { + resolve(JSON.parse(request.response)); + } + else { + error(); + } + } + }; + request.open('GET', '/api/status', true); + request.send(); }); } diff --git a/WebApp/src/pages/dashboard/dashboard-page.tsx b/WebApp/src/pages/dashboard/dashboard-page.tsx index 20855b2..555c321 100644 --- a/WebApp/src/pages/dashboard/dashboard-page.tsx +++ b/WebApp/src/pages/dashboard/dashboard-page.tsx @@ -18,6 +18,7 @@ export class DashboardPage extends Page { async refresh() { this.status = await MonitorApi.get().fetchStatus(); + // todo: update widgets (avoiding to use m.redraw which is a bit costly on CPU) if(this.autoRefresh) setTimeout(() => { if(this.autoRefresh) this.refresh(); }, 500); } diff --git a/WebApp/src/pages/raw-data/raw-data-page.tsx b/WebApp/src/pages/raw-data/raw-data-page.tsx index 432b0ea..ba996c5 100644 --- a/WebApp/src/pages/raw-data/raw-data-page.tsx +++ b/WebApp/src/pages/raw-data/raw-data-page.tsx @@ -19,6 +19,7 @@ export class RawDataPage extends Page { async refresh() { this.status = await MonitorApi.get().fetchStatus(); + m.redraw(); if(this.autoRefresh) setTimeout(() => { if(this.autoRefresh) this.refresh(); }, 500); }