Store Last-Modified dates so Thread Watcher can receive 304 responses on first request.
This commit is contained in:
parent
4b7b139311
commit
d6a6b5d2ac
@ -10,8 +10,8 @@ ThreadWatcher =
|
|||||||
className: 'fa fa-eye'
|
className: 'fa fa-eye'
|
||||||
|
|
||||||
@db = new DataBoard 'watchedThreads', @refresh, true
|
@db = new DataBoard 'watchedThreads', @refresh, true
|
||||||
|
@dbLM = new DataBoard 'watcherLastModified', null, true
|
||||||
@dialog = UI.dialog 'thread-watcher', <%= readHTML('ThreadWatcher.html') %>
|
@dialog = UI.dialog 'thread-watcher', <%= readHTML('ThreadWatcher.html') %>
|
||||||
|
|
||||||
@status = $ '#watcher-status', @dialog
|
@status = $ '#watcher-status', @dialog
|
||||||
@list = @dialog.lastElementChild
|
@list = @dialog.lastElementChild
|
||||||
@refreshButton = $ '.refresh', @dialog
|
@refreshButton = $ '.refresh', @dialog
|
||||||
@ -41,6 +41,7 @@ ThreadWatcher =
|
|||||||
|
|
||||||
Header.addShortcut 'watcher', sc, 510
|
Header.addShortcut 'watcher', sc, 510
|
||||||
|
|
||||||
|
ThreadWatcher.initLastModified()
|
||||||
ThreadWatcher.fetchAuto()
|
ThreadWatcher.fetchAuto()
|
||||||
$.on window, 'visibilitychange focus', -> $.queueTask ThreadWatcher.fetchAuto
|
$.on window, 'visibilitychange focus', -> $.queueTask ThreadWatcher.fetchAuto
|
||||||
|
|
||||||
@ -207,6 +208,17 @@ ThreadWatcher =
|
|||||||
req.abort?()
|
req.abort?()
|
||||||
ThreadWatcher.clearRequests()
|
ThreadWatcher.clearRequests()
|
||||||
|
|
||||||
|
initLastModified: ->
|
||||||
|
lm = ($.lastModified['ThreadWatcher'] or= {})
|
||||||
|
for siteID, boards of ThreadWatcher.dbLM.data
|
||||||
|
for boardID, data of boards.boards
|
||||||
|
if ThreadWatcher.db.get {siteID, boardID}
|
||||||
|
for url, date of data
|
||||||
|
lm[url] = date
|
||||||
|
else
|
||||||
|
ThreadWatcher.dbLM.delete {siteID, boardID}
|
||||||
|
return
|
||||||
|
|
||||||
fetchAuto: ->
|
fetchAuto: ->
|
||||||
clearTimeout ThreadWatcher.timeout
|
clearTimeout ThreadWatcher.timeout
|
||||||
return unless Conf['Auto Update Thread Watcher']
|
return unless Conf['Auto Update Thread Watcher']
|
||||||
@ -247,10 +259,13 @@ ThreadWatcher =
|
|||||||
urlF = if deep and software is 'tinyboard' then 'catalogJSON' else 'threadsListJSON'
|
urlF = if deep and software is 'tinyboard' then 'catalogJSON' else 'threadsListJSON'
|
||||||
url = SW[software]?.urls[urlF]?({siteID, boardID})
|
url = SW[software]?.urls[urlF]?({siteID, boardID})
|
||||||
return unless url
|
return unless url
|
||||||
ThreadWatcher.fetch url, {siteID}, [board], ThreadWatcher.parseBoard
|
ThreadWatcher.fetch url, {siteID}, [board, url], ThreadWatcher.parseBoard
|
||||||
|
|
||||||
parseBoard: (board) ->
|
parseBoard: (board, url) ->
|
||||||
return unless @status is 200
|
return unless @status is 200
|
||||||
|
{siteID, boardID} = board[0]
|
||||||
|
lmDate = @getResponseHeader('Last-Modified')
|
||||||
|
ThreadWatcher.dbLM.extend {siteID, boardID, val: $.item(url, lmDate)}
|
||||||
modified = {}
|
modified = {}
|
||||||
replies = {}
|
replies = {}
|
||||||
try
|
try
|
||||||
@ -259,7 +274,7 @@ ThreadWatcher =
|
|||||||
modified[item.no] = item.last_modified
|
modified[item.no] = item.last_modified
|
||||||
replies[item.no] = item.replies
|
replies[item.no] = item.replies
|
||||||
for thread in board
|
for thread in board
|
||||||
{siteID, boardID, threadID, data} = thread
|
{threadID, data} = thread
|
||||||
if modified[threadID]
|
if modified[threadID]
|
||||||
if modified[threadID] is data.modified and (!replies[threadID]? or replies[threadID] is data.replies)
|
if modified[threadID] is data.modified and (!replies[threadID]? or replies[threadID] is data.replies)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
class DataBoard
|
class DataBoard
|
||||||
@keys = ['hiddenThreads', 'hiddenPosts', 'lastReadPosts', 'yourPosts', 'watchedThreads', 'customTitles']
|
@keys = ['hiddenThreads', 'hiddenPosts', 'lastReadPosts', 'yourPosts', 'watchedThreads', 'watcherLastModified', 'customTitles']
|
||||||
|
|
||||||
constructor: (@key, sync, dontClean) ->
|
constructor: (@key, sync, dontClean) ->
|
||||||
@initData Conf[@key]
|
@initData Conf[@key]
|
||||||
@ -87,7 +87,7 @@ class DataBoard
|
|||||||
|
|
||||||
extend: ({siteID, boardID, threadID, postID, val, rm}, cb) ->
|
extend: ({siteID, boardID, threadID, postID, val, rm}, cb) ->
|
||||||
@save =>
|
@save =>
|
||||||
oldVal = @get {siteID, boardID, threadID, postID, val: {}}
|
oldVal = @get {siteID, boardID, threadID, postID, defaultValue: {}}
|
||||||
delete oldVal[key] for key in rm or []
|
delete oldVal[key] for key in rm or []
|
||||||
$.extend oldVal, val
|
$.extend oldVal, val
|
||||||
@setUnsafe {siteID, boardID, threadID, postID, val: oldVal}
|
@setUnsafe {siteID, boardID, threadID, postID, val: oldVal}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user