Browse Source

disabled mithril redraw for each status request

the goal is to allow each page to finely manage how to update with
minimum CPU usage
master
Youen Toupin 3 years ago
parent
commit
71b87437c7
  1. 18
      WebApp/src/monitor-api.ts
  2. 1
      WebApp/src/pages/dashboard/dashboard-page.tsx
  3. 1
      WebApp/src/pages/raw-data/raw-data-page.tsx

18
WebApp/src/monitor-api.ts

@ -45,11 +45,21 @@ export class MonitorApi {
t: Math.random() * 400 - 100, t: Math.random() * 400 - 100,
alt: Math.random() * 4500000 - 200000 alt: Math.random() * 4500000 - 200000
} }
setTimeout(() => m.redraw(), 0);
} else { } else {
apiStatus = await m.request({ apiStatus = await new Promise<ApiStatus>((resolve, error) => {
method: "GET", let request = new XMLHttpRequest();
url: "/api/status" 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();
}); });
} }

1
WebApp/src/pages/dashboard/dashboard-page.tsx

@ -18,6 +18,7 @@ export class DashboardPage extends Page {
async refresh() { async refresh() {
this.status = await MonitorApi.get().fetchStatus(); this.status = await MonitorApi.get().fetchStatus();
// todo: update widgets (avoiding to use m.redraw which is a bit costly on CPU)
if(this.autoRefresh) if(this.autoRefresh)
setTimeout(() => { if(this.autoRefresh) this.refresh(); }, 500); setTimeout(() => { if(this.autoRefresh) this.refresh(); }, 500);
} }

1
WebApp/src/pages/raw-data/raw-data-page.tsx

@ -19,6 +19,7 @@ export class RawDataPage extends Page {
async refresh() { async refresh() {
this.status = await MonitorApi.get().fetchStatus(); this.status = await MonitorApi.get().fetchStatus();
m.redraw();
if(this.autoRefresh) if(this.autoRefresh)
setTimeout(() => { if(this.autoRefresh) this.refresh(); }, 500); setTimeout(() => { if(this.autoRefresh) this.refresh(); }, 500);
} }

Loading…
Cancel
Save