Skip to content

Commit

Permalink
reduce redraw events
Browse files Browse the repository at this point in the history
  • Loading branch information
dvtate committed May 8, 2023
1 parent 9665898 commit 09209db
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions frontend/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,18 @@ <h2>How it works</h2>
<script src="js/page.bundle.js" async defer></script>
<script>
// Update stats section
(function getStats() {
fetch('/api/public/stats').then(r => r.json()).then(stats => {
document.getElementById('completed-tasks').innerHTML = `${stats.completedTasks} completed tasks`;
document.getElementById('worker-count').innerHTML = `${stats.workers} workers`;
document.getElementById('thread-count').innerHTML = `${stats.threads} threads`;
document.getElementById('load-average').innerHTML = `${stats.loadAverage} load average`;
setTimeout(getStats, 3000);
}).catch(console.error);
let statsJson = '';
(async function getStats() {
const text = await fetch('/api/public/stats').then(r => r.text()).catch(console.error);
if (text != statsJson) {
statsJson = text;
const stats = JSON.parse(statsJson);
document.getElementById('completed-tasks').innerHTML = `${stats.completedTasks.toLocaleString()} completed tasks`;
document.getElementById('worker-count').innerHTML = `${stats.workers.toLocaleString()} workers`;
document.getElementById('thread-count').innerHTML = `${stats.threads.toLocaleString()} threads`;
document.getElementById('load-average').innerHTML = `${stats.loadAverage.toLocaleString()} load average`;
}
return setTimeout(getStats, 1000);
})();
</script>
</body>
Expand Down

0 comments on commit 09209db

Please sign in to comment.