Skip to content

Commit

Permalink
Merge pull request #496 from Automattic/update/normalize-polling-time…
Browse files Browse the repository at this point in the history
…stamp

Round out polling timestamp
  • Loading branch information
philipjohn committed Sep 16, 2018
2 parents 91deb2e + 180b1bc commit 44911f2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/react/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ export function getEntries(page, config, newestEntry) {
}

export function polling(newestEntryTimestamp, config) {
const timestamp = getCurrentTimestamp() + config.timeDifference;
let timestamp = getCurrentTimestamp();

// 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.floor(timestamp / refreshInterval) * refreshInterval;

const settings = {
url: `${config.endpoint_url}entries/${(newestEntryTimestamp + 1) || 0}/${timestamp}/`,
Expand Down

0 comments on commit 44911f2

Please sign in to comment.