Asynchronous version of DataBoard.forceSync.

This commit is contained in:
ccd0 2017-12-10 22:26:43 -08:00
parent f924beb280
commit fbee3c2df2
2 changed files with 19 additions and 10 deletions

View File

@ -196,13 +196,15 @@ ThreadWatcher =
ThreadWatcher.fetchAllStatus()
fetchAllStatus: ->
ThreadWatcher.db.forceSync()
ThreadWatcher.unreaddb.forceSync()
QuoteYou.db?.forceSync()
return unless (threads = ThreadWatcher.getAll()).length
for thread in threads
ThreadWatcher.fetchStatus thread
return
dbs = [ThreadWatcher.db, ThreadWatcher.unreaddb, QuoteYou.db].filter((x) -> x)
n = 0
for db in dbs
db.forceSync ->
if (++n) is dbs.length
threads = ThreadWatcher.getAll()
for thread in threads
ThreadWatcher.fetchStatus thread
return
fetchStatus: (thread, force) ->
{boardID, threadID, data} = thread

View File

@ -29,6 +29,16 @@ class DataBoard
@sync?() if snapshot1 isnt snapshot2
cb?()
forceSync: (cb) ->
snapshot1 = JSON.stringify @data
{changes} = @
$.get @key, {boards: {}}, (items) =>
@data = items[@key]
snapshot2 = JSON.stringify @data
c() for c in changes
@sync?() if snapshot1 isnt snapshot2
cb?()
delete: ({boardID, threadID, postID}) ->
@save =>
if postID
@ -92,9 +102,6 @@ class DataBoard
thread
val or defaultValue
forceSync: ->
$.forceSync @key
clean: ->
for boardID, val of @data.boards
@deleteIfEmpty {boardID}