disabled mithril redraw for each status request

the goal is to allow each page to finely manage how to update with
minimum CPU usage
This commit is contained in:
Youen Toupin 2022-04-09 19:51:44 +02:00
parent f8c2a28c47
commit 71b87437c7
3 changed files with 16 additions and 4 deletions

View File

@ -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();
}); });
} }

View File

@ -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);
} }

View File

@ -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);
} }