From 4c6701f2f7ef4723a5f03d0ec3868464469ac2c9 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 1 Oct 2016 18:09:48 -0700 Subject: [PATCH] Cache filter results so we don't run all OP filters twice. --- src/Filtering/Filter.coffee | 2 ++ src/General/Index.coffee | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Filtering/Filter.coffee b/src/Filtering/Filter.coffee index 861c68630..625cf4959 100644 --- a/src/Filtering/Filter.coffee +++ b/src/Filtering/Filter.coffee @@ -1,5 +1,6 @@ Filter = filters: {} + results: {} init: -> return unless g.VIEW in ['index', 'thread'] and Conf['Filter'] @@ -107,6 +108,7 @@ Filter = settings test: (post, hideable=true) -> + return post.filterResults if post.filterResults hl = undefined top = false for key of Filter.filters when ((value = Filter[key] post)?) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 87f1121ca..b99447d97 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -595,7 +595,7 @@ Index = for data in Index.liveThreadData Index.liveThreadDict[data.no] = data Index.parsedThreads[data.no] = obj = Build.parseJSON data, g.BOARD.ID - results = Filter.test obj + obj.filterResults = results = Filter.test obj obj.isOnTop = results.top obj.isHidden = results.hide if Index.liveThreadData[0] @@ -624,7 +624,9 @@ Index = threads.push thread if not ((OP = thread.OP) and not OP.isFetchedQuote) - OP = new Post Build.postFromObject(threadData, g.BOARD.ID, true), thread, g.BOARD + obj = Index.parsedThreads[threadData.no] + OP = new Post Build.post(obj, true), thread, g.BOARD + OP.filterResults = obj.filterResults posts.push OP thread.setPage i // Index.threadsNumPerPage + 1