From 4b7b13931141db6044b6b44239565ac647cf408f Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 23 Mar 2019 19:19:33 -0700 Subject: [PATCH] Support If-Modified-Since in cross-site thread watcher requests. --- src/Monitoring/ThreadWatcher.coffee | 22 +++++++++------------- src/platform/$.coffee | 4 ++-- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Monitoring/ThreadWatcher.coffee b/src/Monitoring/ThreadWatcher.coffee index da6d04a4a..af2e26b21 100644 --- a/src/Monitoring/ThreadWatcher.coffee +++ b/src/Monitoring/ThreadWatcher.coffee @@ -183,19 +183,15 @@ ThreadWatcher = else ThreadWatcher.status.textContent = "#{Math.round(ThreadWatcher.fetched / ThreadWatcher.requests.length * 100)}%" cb.apply @, args - if siteID is Site.hostname - if force - delete $.lastModified.ThreadWatcher?[url] - req = $.whenModified( - url, - 'ThreadWatcher', - onloadend, - {timeout: $.MINUTE} - ) - else - req = CrossOrigin.ajax url, - onloadend: onloadend - timeout: $.MINUTE + ajax = if siteID is Site.hostname then $.ajax else CrossOrigin.ajax + if force + delete $.lastModified.ThreadWatcher?[url] + req = $.whenModified( + url, + 'ThreadWatcher', + onloadend, + {timeout: $.MINUTE, ajax} + ) ThreadWatcher.requests.push req clearRequests: -> diff --git a/src/platform/$.coffee b/src/platform/$.coffee index 8e7772478..257942d07 100644 --- a/src/platform/$.coffee +++ b/src/platform/$.coffee @@ -82,7 +82,7 @@ $.ajax = do -> # This saves a lot of bandwidth and CPU time for both the users and the servers. $.lastModified = {} $.whenModified = (url, bucket, cb, options={}) -> - {timeout} = options + {timeout, ajax} = options params = [] # XXX https://bugs.chromium.org/p/chromium/issues/detail?id=643659 params.push "s=#{bucket}" if $.engine is 'blink' @@ -92,7 +92,7 @@ $.whenModified = (url, bucket, cb, options={}) -> headers = {} if (t = $.lastModified[bucket]?[url0])? headers['If-Modified-Since'] = t - r = $.ajax url, { + r = (ajax or $.ajax) url, { onloadend: -> ($.lastModified[bucket] or= {})[url0] = @getResponseHeader('Last-Modified') cb.call @