More index tweaking/optimization and small thread hiding fix.

Most feature that need to be called on each index refresh don't need
to be called on every single page build, but only after building the
threads. ThreadHiding needs to be fired on each page build to ensure
that the stub summaries fit with the number of replies, so it has to
wait for the last replies to be added. This also fixes the bug where
ThreadHiding was creating one extra stub on each IndexRefresh event.
This commit is contained in:
Mayhem 2013-11-05 01:03:09 +01:00
parent 8f56d3e415
commit f09121ab2e
2 changed files with 11 additions and 8 deletions

View File

@ -4,7 +4,7 @@ ThreadHiding =
@db = new DataBoard 'hiddenThreads' @db = new DataBoard 'hiddenThreads'
@syncCatalog() @syncCatalog()
$.on d, 'IndexRefresh', @onrefresh $.on d, 'IndexBuild', @onIndexBuild
Thread.callbacks.push Thread.callbacks.push
name: 'Thread Hiding' name: 'Thread Hiding'
cb: @node cb: @node
@ -15,13 +15,15 @@ ThreadHiding =
return unless Conf['Thread Hiding'] return unless Conf['Thread Hiding']
$.prepend @OP.nodes.root, ThreadHiding.makeButton @, 'hide' $.prepend @OP.nodes.root, ThreadHiding.makeButton @, 'hide'
onrefresh: -> onIndexBuild: ({detail: nodes}) ->
for threadID, thread of g.BOARD.threads when thread.isHidden for root, i in nodes by 2
root = thread.OP.nodes.root.parentNode thread = Get.threadFromRoot root
if thread.stub continue unless thread.isHidden
unless thread.stub
nodes[i + 1].hidden = true
else unless root.contains thread.stub
# When we come back to a page, the stub is already there.
ThreadHiding.makeStub thread, root ThreadHiding.makeStub thread, root
else
root.nextElementSibling.hidden = true
return return
syncCatalog: -> syncCatalog: ->

View File

@ -227,6 +227,7 @@ Index =
$.nodes Index.nodes $.nodes Index.nodes
Main.callbackNodes Thread, threads Main.callbackNodes Thread, threads
Main.callbackNodes Post, posts Main.callbackNodes Post, posts
$.event 'IndexRefresh'
buildReplies: (threadRoots) -> buildReplies: (threadRoots) ->
posts = [] posts = []
for threadRoot in threadRoots by 2 for threadRoot in threadRoots by 2
@ -291,5 +292,5 @@ Index =
nodes = Index.sortedNodes nodes = Index.sortedNodes
$.rmAll Index.root $.rmAll Index.root
Index.buildReplies nodes Index.buildReplies nodes
$.event 'IndexRefresh' $.event 'IndexBuild', nodes
$.add Index.root, nodes $.add Index.root, nodes