Occasionally check catalog.json on vichan boards due to last_modified API bug.
Also let manual thread watcher checks set lastChecked.
This commit is contained in:
parent
7a8615d51c
commit
5a49280be4
@ -212,7 +212,6 @@ ThreadWatcher =
|
|||||||
now = Date.now()
|
now = Date.now()
|
||||||
unless now - interval < (db.data.lastChecked or 0) <= now or d.hidden or not d.hasFocus()
|
unless now - interval < (db.data.lastChecked or 0) <= now or d.hidden or not d.hasFocus()
|
||||||
ThreadWatcher.fetchAllStatus()
|
ThreadWatcher.fetchAllStatus()
|
||||||
db.setLastChecked()
|
|
||||||
ThreadWatcher.timeout = setTimeout ThreadWatcher.fetchAuto, interval
|
ThreadWatcher.timeout = setTimeout ThreadWatcher.fetchAuto, interval
|
||||||
|
|
||||||
buttonFetchAll: ->
|
buttonFetchAll: ->
|
||||||
@ -224,33 +223,43 @@ ThreadWatcher =
|
|||||||
fetchAllStatus: ->
|
fetchAllStatus: ->
|
||||||
dbs = [ThreadWatcher.db, ThreadWatcher.unreaddb, QuoteYou.db].filter((x) -> x)
|
dbs = [ThreadWatcher.db, ThreadWatcher.unreaddb, QuoteYou.db].filter((x) -> x)
|
||||||
n = 0
|
n = 0
|
||||||
for db in dbs
|
for dbi in dbs
|
||||||
db.forceSync ->
|
dbi.forceSync ->
|
||||||
if (++n) is dbs.length
|
if (++n) is dbs.length
|
||||||
|
# XXX On vichan boards, last_modified field of threads.json does not account for sage posts.
|
||||||
|
# Occasionally check replies field of catalog.json to find these posts.
|
||||||
|
{db} = ThreadWatcher
|
||||||
|
now = Date.now()
|
||||||
|
deep = !(now - 2 * $.HOUR < (db.data.lastChecked2 or 0) <= now)
|
||||||
boards = ThreadWatcher.getAll(true)
|
boards = ThreadWatcher.getAll(true)
|
||||||
for board in boards
|
for board in boards
|
||||||
ThreadWatcher.fetchBoard board
|
ThreadWatcher.fetchBoard board, deep
|
||||||
return
|
db.setLastChecked()
|
||||||
|
db.setLastChecked('lastChecked2') if deep
|
||||||
|
|
||||||
fetchBoard: (board) ->
|
fetchBoard: (board, deep) ->
|
||||||
return unless board.some (thread) -> !thread.data.isDead
|
return unless board.some (thread) -> !thread.data.isDead
|
||||||
{siteID, boardID} = board[0]
|
{siteID, boardID} = board[0]
|
||||||
software = Conf['siteProperties'][siteID]?.software
|
software = Conf['siteProperties'][siteID]?.software
|
||||||
url = SW[software]?.urls.threadsListJSON?({siteID, boardID})
|
urlF = if deep and software is 'tinyboard' then 'catalogJSON' else 'threadsListJSON'
|
||||||
|
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], ThreadWatcher.parseBoard
|
||||||
|
|
||||||
parseBoard: (board) ->
|
parseBoard: (board) ->
|
||||||
return unless @status is 200
|
return unless @status is 200
|
||||||
modified = {}
|
modified = {}
|
||||||
|
replies = {}
|
||||||
try
|
try
|
||||||
for page in @response
|
for page in @response
|
||||||
for item in page.threads
|
for item in page.threads
|
||||||
modified[item.no] = item.last_modified
|
modified[item.no] = item.last_modified
|
||||||
|
replies[item.no] = item.replies
|
||||||
for thread in board
|
for thread in board
|
||||||
{siteID, boardID, threadID} = thread
|
{siteID, boardID, threadID, data} = thread
|
||||||
if modified[threadID]
|
if modified[threadID]
|
||||||
continue if thread.data.modified is modified[threadID]
|
if modified[threadID] is data.modified and (!replies[threadID]? or replies[threadID] is data.replies)
|
||||||
|
continue
|
||||||
ThreadWatcher.db.extend {siteID, boardID, threadID, val: {modified: modified[threadID]}}
|
ThreadWatcher.db.extend {siteID, boardID, threadID, val: {modified: modified[threadID]}}
|
||||||
ThreadWatcher.fetchStatus thread
|
ThreadWatcher.fetchStatus thread
|
||||||
return
|
return
|
||||||
@ -269,6 +278,7 @@ ThreadWatcher =
|
|||||||
|
|
||||||
if @status is 200 and @response
|
if @status is 200 and @response
|
||||||
last = @response.posts[@response.posts.length-1].no
|
last = @response.posts[@response.posts.length-1].no
|
||||||
|
replies = @response.posts.length-1
|
||||||
isDead = !!@response.posts[0].archived
|
isDead = !!@response.posts[0].archived
|
||||||
if isDead and Conf['Auto Prune']
|
if isDead and Conf['Auto Prune']
|
||||||
ThreadWatcher.db.delete {siteID, boardID, threadID}
|
ThreadWatcher.db.delete {siteID, boardID, threadID}
|
||||||
@ -310,7 +320,7 @@ ThreadWatcher =
|
|||||||
quotingYou = true
|
quotingYou = true
|
||||||
|
|
||||||
updated = (isDead isnt data.isDead or unread isnt data.unread or quotingYou isnt data.quotingYou)
|
updated = (isDead isnt data.isDead or unread isnt data.unread or quotingYou isnt data.quotingYou)
|
||||||
ThreadWatcher.db.extend {siteID, boardID, threadID, val: {last, isDead, unread, quotingYou}}
|
ThreadWatcher.db.extend {siteID, boardID, threadID, val: {last, replies, isDead, unread, quotingYou}}
|
||||||
ThreadWatcher.refresh() if updated
|
ThreadWatcher.refresh() if updated
|
||||||
|
|
||||||
else if @status is 404
|
else if @status is 404
|
||||||
|
|||||||
@ -93,9 +93,9 @@ class DataBoard
|
|||||||
@setUnsafe {siteID, boardID, threadID, postID, val: oldVal}
|
@setUnsafe {siteID, boardID, threadID, postID, val: oldVal}
|
||||||
, cb
|
, cb
|
||||||
|
|
||||||
setLastChecked: ->
|
setLastChecked: (key='lastChecked') ->
|
||||||
@save =>
|
@save =>
|
||||||
@data.lastChecked = Date.now()
|
@data[key] = Date.now()
|
||||||
|
|
||||||
get: ({siteID, boardID, threadID, postID, defaultValue}) ->
|
get: ({siteID, boardID, threadID, postID, defaultValue}) ->
|
||||||
siteID or= Site.hostname
|
siteID or= Site.hostname
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user