Only build the threads we need.

This commit is contained in:
ccd0 2016-10-01 20:46:02 -07:00
parent 80b350b3a6
commit 293fca67dd

View File

@ -160,7 +160,7 @@ Index =
return Index.endNotice() if pageNum > Index.pagesNum return Index.endNotice() if pageNum > Index.pagesNum
threadIDs = Index.threadsOnPage pageNum threadIDs = Index.threadsOnPage pageNum
threads = threadIDs.map (ID) -> g.BOARD.threads[ID] threads = Index.buildThreads threadIDs
Index.buildStructure threads Index.buildStructure threads
endNotice: do -> endNotice: do ->
@ -268,8 +268,6 @@ Index =
Index.buildIndex() if e Index.buildIndex() if e
replies: -> replies: ->
Index.buildThreads()
Index.sort()
Index.buildIndex() Index.buildIndex()
hover: (e) -> hover: (e) ->
@ -581,7 +579,6 @@ Index =
parse: (pages) -> parse: (pages) ->
$.cleanCache (url) -> /^\/\/a\.4cdn\.org\//.test url $.cleanCache (url) -> /^\/\/a\.4cdn\.org\//.test url
Index.parseThreadList pages Index.parseThreadList pages
Index.buildThreads()
Index.changed.threads = true Index.changed.threads = true
Index.pageLoad() Index.pageLoad()
@ -612,13 +609,15 @@ Index =
else else
Index.parsedThreads[threadID].isHidden Index.parsedThreads[threadID].isHidden
buildThreads: -> buildThreads: (threadIDs) ->
return unless Index.liveThreadData threads = []
threads = [] newThreads = []
posts = [] newPosts = []
for threadData in Index.liveThreadData for ID in threadIDs
try try
if (thread = g.BOARD.threads[threadData.no]) threadData = Index.liveThreadDict[ID]
if (thread = g.BOARD.threads[ID])
thread.setCount 'post', threadData.replies + 1, threadData.bumplimit thread.setCount 'post', threadData.replies + 1, threadData.bumplimit
thread.setCount 'file', threadData.images + !!threadData.ext, threadData.imagelimit thread.setCount 'file', threadData.images + !!threadData.ext, threadData.imagelimit
thread.setStatus 'Sticky', !!threadData.sticky thread.setStatus 'Sticky', !!threadData.sticky
@ -627,15 +626,16 @@ Index =
$.rm thread.catalogView.nodes.replies $.rm thread.catalogView.nodes.replies
thread.catalogView.nodes.replies = null thread.catalogView.nodes.replies = null
else else
thread = new Thread threadData.no, g.BOARD thread = new Thread ID, g.BOARD
threads.push thread newThreads.push thread
threads.push thread
if not ((OP = thread.OP) and not OP.isFetchedQuote) if not ((OP = thread.OP) and not OP.isFetchedQuote)
obj = Index.parsedThreads[threadData.no] obj = Index.parsedThreads[ID]
OP = new Post Build.post(obj, true), thread, g.BOARD OP = new Post Build.post(obj, true), thread, g.BOARD
OP.filterResults = obj.filterResults OP.filterResults = obj.filterResults
posts.push OP newPosts.push OP
thread.setPage(Index.threadPosition[threadData.no] // Index.threadsNumPerPage + 1) thread.setPage(Index.threadPosition[ID] // Index.threadsNumPerPage + 1)
Build.thread thread, threadData Build.thread thread, threadData
catch err catch err
@ -646,11 +646,13 @@ Index =
error: err error: err
Main.handleErrors errors if errors Main.handleErrors errors if errors
Main.callbackNodes 'Thread', threads Main.callbackNodes 'Thread', newThreads
Main.callbackNodes 'Post', posts Main.callbackNodes 'Post', newPosts
Index.updateHideLabel() Index.updateHideLabel()
$.event 'IndexRefreshInternal' $.event 'IndexRefreshInternal'
threads
buildReplies: (threads) -> buildReplies: (threads) ->
posts = [] posts = []
for thread in threads for thread in threads
@ -765,7 +767,7 @@ Index =
threadIDs = Index.sortedThreadIDs.filter (ID) -> !Index.isHidden(ID) isnt Index.showHiddenThreads threadIDs = Index.sortedThreadIDs.filter (ID) -> !Index.isHidden(ID) isnt Index.showHiddenThreads
else else
threadIDs = Index.threadsOnPage Index.currentPage threadIDs = Index.threadsOnPage Index.currentPage
threads = threadIDs.map (ID) -> g.BOARD.threads[ID] threads = Index.buildThreads threadIDs
delete Index.pageNum delete Index.pageNum
$.rmAll Index.root $.rmAll Index.root
$.rmAll Header.hover $.rmAll Header.hover