From f09121ab2eb88cd7671ab0559d9898865251c8ca Mon Sep 17 00:00:00 2001 From: Mayhem Date: Tue, 5 Nov 2013 01:03:09 +0100 Subject: [PATCH] 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. --- src/Filtering/ThreadHiding.coffee | 16 +++++++++------- src/General/Index.coffee | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Filtering/ThreadHiding.coffee b/src/Filtering/ThreadHiding.coffee index c225c0056..920bfe4f2 100644 --- a/src/Filtering/ThreadHiding.coffee +++ b/src/Filtering/ThreadHiding.coffee @@ -4,7 +4,7 @@ ThreadHiding = @db = new DataBoard 'hiddenThreads' @syncCatalog() - $.on d, 'IndexRefresh', @onrefresh + $.on d, 'IndexBuild', @onIndexBuild Thread.callbacks.push name: 'Thread Hiding' cb: @node @@ -15,13 +15,15 @@ ThreadHiding = return unless Conf['Thread Hiding'] $.prepend @OP.nodes.root, ThreadHiding.makeButton @, 'hide' - onrefresh: -> - for threadID, thread of g.BOARD.threads when thread.isHidden - root = thread.OP.nodes.root.parentNode - if thread.stub + onIndexBuild: ({detail: nodes}) -> + for root, i in nodes by 2 + thread = Get.threadFromRoot root + 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 - else - root.nextElementSibling.hidden = true return syncCatalog: -> diff --git a/src/General/Index.coffee b/src/General/Index.coffee index c5df4b32c..60dfed9e9 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -227,6 +227,7 @@ Index = $.nodes Index.nodes Main.callbackNodes Thread, threads Main.callbackNodes Post, posts + $.event 'IndexRefresh' buildReplies: (threadRoots) -> posts = [] for threadRoot in threadRoots by 2 @@ -291,5 +292,5 @@ Index = nodes = Index.sortedNodes $.rmAll Index.root Index.buildReplies nodes - $.event 'IndexRefresh' + $.event 'IndexBuild', nodes $.add Index.root, nodes