Automattic / liveblog

Liveblogging done right. Using WordPress.
https://wordpress.org/plugins/liveblog/
308 stars 123 forks source link

Liveblog updates evading caches #489

Open philipjohn opened 6 years ago

philipjohn commented 6 years ago

The timestamps used by Liveblog result in many unique requests that are often uncacheable. We need to instead limit requests to time buckets of (for exampe) 10 seconds so that caches can more often serve up cached responses.

Here's a draft patch to expand on (props @darthhexx ):

diff --git a/src/react/services/api.js b/src/react/services/api.js
index d0f307d..2d7c43a 100644
--- a/src/react/services/api.js
+++ b/src/react/services/api.js
@@ -21,8 +21,8 @@ export function getEntries(page, config, newestEntry) {
 }

 export function polling(newestEntryTimestamp, config) {
-  const timestamp = getCurrentTimestamp() + config.timeDifference;
-
+  let timestamp = getCurrentTimestamp() + config.timeDifference;
+  timestamp = timestamp + ( config.timeDifference - ( timestamp % config.timeDifference ) );
   const settings = {
     url: `${config.endpoint_url}entries/${(newestEntryTimestamp + 1) || 0}/${timestamp}/`,
     method: 'GET',
paulschreiber commented 6 years ago

See also @mjangda's patch at https://github.com/Automattic/liveblog/pull/496

philipjohn commented 5 years ago

Resolved by #496

mjangda commented 5 years ago

I don't think this is quite fixed yet and needs more research + testing.

philipjohn commented 5 years ago

Cool, chatting with Nick on Monday and I have some ideas for tests that we can talk through then.