Skip to content

Commit 2700bbf

Browse files
committed
Reduce web update interval
Signed-off-by: Asriel Camora <asriel@camora.dev>
1 parent 6c37914 commit 2700bbf

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

web/static/assets/main.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ function format_relative_past(time) {
3636
if (diff < 1000) {
3737
return 'Just now';
3838
}
39-
return humanizeDuration(diff, { largest: 2, round: true }) + ' ago';
39+
return `${humanizeDuration(diff, { largest: 2, round: true })} ago`;
4040
}
4141

4242
function format_future_duration(diff) {
4343
if (diff < 500) {
4444
return 'soon';
4545
}
46-
return 'in ' + humanizeDuration(diff, { largest: 2, round: true });
46+
return `in ${humanizeDuration(diff, { largest: 2, round: true })}`;
4747
}
4848

4949
function update_global_row(row, text) {
@@ -52,11 +52,11 @@ function update_global_row(row, text) {
5252
}
5353

5454
function get_region_section_a(region_id) {
55-
let ret = region_hyperlinks.querySelector('#region-a-' + region_id);
55+
let ret = region_hyperlinks.querySelector(`#region-a-${region_id}`);
5656
if (ret === null) {
5757
ret = create_hierarchy({
5858
"tag": "li",
59-
"id": "region-a-" + region_id,
59+
"id": `region-a-${region_id}`,
6060
"class_name": "hide-mobile",
6161
"children": [
6262
{
@@ -72,11 +72,11 @@ function get_region_section_a(region_id) {
7272
return ret.querySelector('a');
7373
}
7474
function get_region_section_b(region_id) {
75-
let ret = region_dropdown.querySelector('#region-b-' + region_id);
75+
let ret = region_dropdown.querySelector(`#region-b-${region_id}`);
7676
if (ret === null) {
7777
ret = create_hierarchy({
7878
"tag": "li",
79-
"id": "region-b-" + region_id,
79+
"id": `region-b-${region_id}`,
8080
"children": [
8181
{
8282
"tag": "a",
@@ -94,11 +94,11 @@ function get_region_section_b(region_id) {
9494
}
9595

9696
function get_dc_section(datacenter_id) {
97-
let ret = main.querySelector('#dc-' + datacenter_id);
97+
let ret = main.querySelector(`#dc-${datacenter_id}`);
9898
if (ret === null) {
9999
ret = create_hierarchy({
100100
"tag": "section",
101-
"id": "dc-" + datacenter_id,
101+
"id": `dc-${datacenter_id}`,
102102
"children": [
103103
{
104104
"tag": "hgroup",
@@ -127,15 +127,15 @@ function get_dc_section(datacenter_id) {
127127
function get_world_row(datacenter_id, world_id) {
128128
let dc_section = get_dc_section(datacenter_id);
129129

130-
let ret = dc_section.querySelector('#world-' + world_id);
130+
let ret = dc_section.querySelector(`#world-${world_id}`);
131131
if (ret === null) {
132132
ret = create_hierarchy({
133133
"tag": "div",
134134
"class_name": "shadow-container",
135135
"children": [
136136
{
137137
"tag": "article",
138-
"id": "world-" + world_id,
138+
"id": `world-${world_id}`,
139139
"children": [
140140
{
141141
"tag": "header",
@@ -368,7 +368,8 @@ function update_dc_data(data, regions) {
368368
function update_region_data(data, datacenters) {
369369
for (let section of [get_region_section_a(data.id), get_region_section_b(data.id)]) {
370370
section.textContent = data.name;
371-
section.setAttribute('href', '#dc-' + datacenters.find(dc => dc.region_id === data.id).id);
371+
let dc_id = datacenters.find(dc => dc.region_id === data.id).id;
372+
section.setAttribute('href', `#dc-${dc_id}`);
372373
}
373374
}
374375

@@ -444,23 +445,24 @@ function update_from_url(url) {
444445
}
445446

446447
function queue_url_update(url) {
448+
const REFRESH_INTERVAL = 15000;
447449
let now = Date.now();
448450
let timerId = setInterval(() => {
449451
// Don't update in the background
450452
if (document.visibilityState === 'hidden') {
451453
return;
452454
}
453455
let diff = Date.now() - now;
454-
if (diff >= 30000) {
456+
if (diff >= REFRESH_INTERVAL) {
455457
timer_circle.removeAttribute('stroke-dashoffset');
456458
timer_container.setAttribute('data-tooltip', `Reloading`);
457459
clearInterval(timerId);
458460
update_from_url(url);
459461
}
460462
else {
461-
let percent = diff / 30000;
463+
let percent = diff / REFRESH_INTERVAL;
462464
timer_circle.setAttribute('stroke-dashoffset', -9 * 2 * Math.PI * percent);
463-
timer_container.setAttribute('data-tooltip', `Reloading ${format_future_duration(30000 - diff)}`);
465+
timer_container.setAttribute('data-tooltip', `Reloading ${format_future_duration(REFRESH_INTERVAL - diff)}`);
464466
}
465467
}, 100);
466468
timer_group.classList.remove('timer-reloading');

0 commit comments

Comments
 (0)