Make first part of catalog load faster.

This commit is contained in:
ccd0 2016-10-02 04:31:13 -07:00
parent ddb0c3b048
commit d69775ed39

View File

@ -129,7 +129,7 @@ Index =
board = $ '.board' board = $ '.board'
$.replace board, Index.root $.replace board, Index.root
if Index.liveThreadData if Index.loaded
$.event 'PostsInserted' $.event 'PostsInserted'
# Hacks: # Hacks:
# - When removing an element from the document during page load, # - When removing an element from the document during page load,
@ -681,11 +681,11 @@ Index =
catalogThreads = [] catalogThreads = []
for thread in threads when !thread.catalogView for thread in threads when !thread.catalogView
{ID} = thread {ID} = thread
i = Index.threadPosition[ID]
page = Index.threadPosition[ID] // Index.threadsNumPerPage + 1 page = Index.threadPosition[ID] // Index.threadsNumPerPage + 1
root = Build.catalogThread thread, Index.liveThreadDict[ID], page root = Build.catalogThread thread, Index.liveThreadDict[ID], page
catalogThreads.push new CatalogThread root, thread catalogThreads.push new CatalogThread root, thread
Main.callbackNodes 'CatalogThread', catalogThreads Main.callbackNodes 'CatalogThread', catalogThreads
return
sizeCatalogViews: (threads) -> sizeCatalogViews: (threads) ->
# XXX When browsers support CSS3 attr(), use it instead. # XXX When browsers support CSS3 attr(), use it instead.
@ -775,6 +775,7 @@ Index =
Index.buildCatalog threadIDs Index.buildCatalog threadIDs
else else
Index.buildStructure threadIDs Index.buildStructure threadIDs
return
threadsOnPage: (pageNum) -> threadsOnPage: (pageNum) ->
nodesPerPage = Index.threadsNumPerPage nodesPerPage = Index.threadsNumPerPage
@ -788,10 +789,28 @@ Index =
for thread in threads for thread in threads
nodes.push thread.nodes.root, $.el('hr') nodes.push thread.nodes.root, $.el('hr')
$.add Index.root, nodes $.add Index.root, nodes
if doc.contains Index.root if Index.root.parentNode
$.event 'PostsInserted' $.event 'PostsInserted'
Index.loaded = true
return
buildCatalog: (threadIDs) -> buildCatalog: (threadIDs) ->
i = 0
n = threadIDs.length
fn = ->
j = if i > 0 and Index.root.parentNode then n else i + 25
Index.buildCatalogPart threadIDs[i...j]
i = j
if i < n
$.queueTask fn
else
if Index.root.parentNode
$.event 'PostsInserted'
Index.loaded = true
fn()
return
buildCatalogPart: (threadIDs) ->
threads = Index.buildThreads threadIDs threads = Index.buildThreads threadIDs
Index.buildCatalogViews threads Index.buildCatalogViews threads
Index.sizeCatalogViews threads Index.sizeCatalogViews threads
@ -802,8 +821,7 @@ Index =
$.add thread.catalogView.nodes.root, thread.OP.nodes.root $.add thread.catalogView.nodes.root, thread.OP.nodes.root
nodes.push thread.catalogView.nodes.root nodes.push thread.catalogView.nodes.root
$.add Index.root, nodes $.add Index.root, nodes
if doc.contains Index.root return
$.event 'PostsInserted'
clearSearch: -> clearSearch: ->
Index.searchInput.value = '' Index.searchInput.value = ''