Support If-Modified-Since in cross-site thread watcher requests.

This commit is contained in:
ccd0 2019-03-23 19:19:33 -07:00
parent 7b2dee7279
commit 4b7b139311
2 changed files with 11 additions and 15 deletions

View File

@ -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: ->

View File

@ -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 @