From 779c23fada5092e614ec132add9864a9735f464b Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Tue, 10 Jul 2018 17:37:03 -0400 Subject: [PATCH 1/3] Round out polling timestamp Rather than a random scatter of timestamps, we can get a much higher cache hit-rate by forcing/normalizing multiple clients to make a request with the same timestamp. --- src/react/services/api.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/react/services/api.js b/src/react/services/api.js index d0f307d07..9790c008e 100644 --- a/src/react/services/api.js +++ b/src/react/services/api.js @@ -21,7 +21,13 @@ export function getEntries(page, config, newestEntry) { } export function polling(newestEntryTimestamp, config) { - const timestamp = getCurrentTimestamp() + config.timeDifference; + let timestamp = getCurrentTimestamp() + config.timeDifference; + + // Round out the timestamp to get a higher cache hitrate. + // Rather than a random scatter of timestamps, + // this allows multiple clients to make a request with the same timestamp. + const refreshInterval = parseInt(config.refresh_interval, 10); + timestamp = Math.round(timestamp / refreshInterval) * refreshInterval; const settings = { url: `${config.endpoint_url}entries/${(newestEntryTimestamp + 1) || 0}/${timestamp}/`, From 37df496431ed255a5a9ccbebf3bddf72c4f89027 Mon Sep 17 00:00:00 2001 From: Philip John Date: Sat, 8 Sep 2018 12:16:20 +0100 Subject: [PATCH 2/3] Use floor() instead of round() to avoid future timestamps. --- src/react/services/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/react/services/api.js b/src/react/services/api.js index 9790c008e..bdb3ffb63 100644 --- a/src/react/services/api.js +++ b/src/react/services/api.js @@ -27,7 +27,7 @@ export function polling(newestEntryTimestamp, config) { // Rather than a random scatter of timestamps, // this allows multiple clients to make a request with the same timestamp. const refreshInterval = parseInt(config.refresh_interval, 10); - timestamp = Math.round(timestamp / refreshInterval) * refreshInterval; + timestamp = Math.floor(timestamp / refreshInterval) * refreshInterval; const settings = { url: `${config.endpoint_url}entries/${(newestEntryTimestamp + 1) || 0}/${timestamp}/`, From 180b1bc2c4c984f24051c32a19e1ad505328ea8f Mon Sep 17 00:00:00 2001 From: Philip John Date: Sun, 16 Sep 2018 20:27:29 +0100 Subject: [PATCH 3/3] Remove time difference from timestamp as per discussion on #496 --- src/react/services/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/react/services/api.js b/src/react/services/api.js index bdb3ffb63..15b4edd8c 100644 --- a/src/react/services/api.js +++ b/src/react/services/api.js @@ -21,7 +21,7 @@ export function getEntries(page, config, newestEntry) { } export function polling(newestEntryTimestamp, config) { - let timestamp = getCurrentTimestamp() + config.timeDifference; + let timestamp = getCurrentTimestamp(); // Round out the timestamp to get a higher cache hitrate. // Rather than a random scatter of timestamps,