Optimize the index by using a sorted list of threads instead of nodes.
Only one call to Get.threadFromRoot() per thread now.
This commit is contained in:
parent
27fa3f2bf7
commit
49c9156c30
@ -345,7 +345,7 @@ Index =
|
|||||||
else
|
else
|
||||||
Index.threadsNumPerPage
|
Index.threadsNumPerPage
|
||||||
getPagesNum: ->
|
getPagesNum: ->
|
||||||
Math.ceil Index.sortedNodes.length / Index.getThreadsNumPerPage()
|
Math.ceil Index.sortedThreads.length / Index.getThreadsNumPerPage()
|
||||||
getMaxPageNum: ->
|
getMaxPageNum: ->
|
||||||
Math.max 0, Index.getPagesNum() - 1
|
Math.max 0, Index.getPagesNum() - 1
|
||||||
togglePagelist: ->
|
togglePagelist: ->
|
||||||
@ -519,11 +519,10 @@ Index =
|
|||||||
for i in [0...threadRoots.length] by 1
|
for i in [0...threadRoots.length] by 1
|
||||||
threadRoots.splice (i * 2) + 1, 0, $.el 'hr'
|
threadRoots.splice (i * 2) + 1, 0, $.el 'hr'
|
||||||
return
|
return
|
||||||
buildReplies: (threadRoots) ->
|
buildReplies: (threads) ->
|
||||||
return unless Conf['Show Replies']
|
return unless Conf['Show Replies']
|
||||||
posts = []
|
posts = []
|
||||||
for threadRoot in threadRoots
|
for thread in threads
|
||||||
thread = Get.threadFromRoot threadRoot
|
|
||||||
i = Index.liveThreadIDs.indexOf thread.ID
|
i = Index.liveThreadIDs.indexOf thread.ID
|
||||||
continue unless lastReplies = Index.liveThreadData[i].last_replies
|
continue unless lastReplies = Index.liveThreadData[i].last_replies
|
||||||
nodes = []
|
nodes = []
|
||||||
@ -540,17 +539,16 @@ Index =
|
|||||||
errors.push
|
errors.push
|
||||||
message: "Parsing of Post No.#{data.no} failed. Post will be skipped."
|
message: "Parsing of Post No.#{data.no} failed. Post will be skipped."
|
||||||
error: err
|
error: err
|
||||||
$.add threadRoot, nodes
|
$.add thread.OP.nodes.root.parentNode, nodes
|
||||||
|
|
||||||
Main.handleErrors errors if errors
|
Main.handleErrors errors if errors
|
||||||
Main.callbackNodes Post, posts
|
Main.callbackNodes Post, posts
|
||||||
buildCatalogViews: ->
|
buildCatalogViews: ->
|
||||||
threads = Index.sortedNodes.map (threadRoot) -> Get.threadFromRoot threadRoot
|
|
||||||
catalogThreads = []
|
catalogThreads = []
|
||||||
for thread in threads when !thread.catalogView
|
for thread in Index.sortedThreads when !thread.catalogView
|
||||||
catalogThreads.push new CatalogThread Build.catalogThread(thread), thread
|
catalogThreads.push new CatalogThread Build.catalogThread(thread), thread
|
||||||
Main.callbackNodes CatalogThread, catalogThreads
|
Main.callbackNodes CatalogThread, catalogThreads
|
||||||
threads.map (thread) -> thread.catalogView.nodes.root
|
Index.sortedThreads.map (thread) -> thread.catalogView.nodes.root
|
||||||
sizeCatalogViews: (nodes) ->
|
sizeCatalogViews: (nodes) ->
|
||||||
# XXX When browsers support CSS3 attr(), use it instead.
|
# XXX When browsers support CSS3 attr(), use it instead.
|
||||||
size = if Conf['Index Size'] is 'small' then 150 else 250
|
size = if Conf['Index Size'] is 'small' then 150 else 250
|
||||||
@ -578,19 +576,19 @@ Index =
|
|||||||
sortedThreadIDs = [Index.liveThreadData...].sort((a, b) -> b.replies - a.replies).map (data) -> data.no
|
sortedThreadIDs = [Index.liveThreadData...].sort((a, b) -> b.replies - a.replies).map (data) -> data.no
|
||||||
when 'filecount'
|
when 'filecount'
|
||||||
sortedThreadIDs = [Index.liveThreadData...].sort((a, b) -> b.images - a.images).map (data) -> data.no
|
sortedThreadIDs = [Index.liveThreadData...].sort((a, b) -> b.images - a.images).map (data) -> data.no
|
||||||
Index.sortedNodes = sortedThreadIDs
|
Index.sortedThreads = sortedThreadIDs
|
||||||
.map (threadID) -> Index.nodes[Index.liveThreadIDs.indexOf threadID]
|
.map (threadID) -> Get.threadFromRoot Index.nodes[Index.liveThreadIDs.indexOf threadID]
|
||||||
.filter (threadRoot) -> Get.threadFromRoot(threadRoot).isHidden is Index.showHiddenThreads
|
.filter (thread) -> thread.isHidden is Index.showHiddenThreads
|
||||||
if Index.isSearching
|
if Index.isSearching
|
||||||
Index.sortedNodes = Index.querySearch(Index.searchInput.value) or Index.sortedNodes
|
Index.sortedThreads = Index.querySearch(Index.searchInput.value) or Index.sortedThreads
|
||||||
# Sticky threads
|
# Sticky threads
|
||||||
Index.sortOnTop (thread) -> thread.isSticky
|
Index.sortOnTop (thread) -> thread.isSticky
|
||||||
# Highlighted threads
|
# Highlighted threads
|
||||||
Index.sortOnTop (thread) -> thread.isOnTop or thread.isPinned
|
Index.sortOnTop (thread) -> thread.isOnTop or thread.isPinned
|
||||||
sortOnTop: (match) ->
|
sortOnTop: (match) ->
|
||||||
offset = 0
|
offset = 0
|
||||||
for threadRoot, i in Index.sortedNodes when match Get.threadFromRoot threadRoot
|
for thread, i in Index.sortedThreads when match thread
|
||||||
Index.sortedNodes.splice offset++, 0, Index.sortedNodes.splice(i, 1)[0]
|
Index.sortedThreads.splice offset++, 0, Index.sortedThreads.splice(i, 1)[0]
|
||||||
return
|
return
|
||||||
buildIndex: ->
|
buildIndex: ->
|
||||||
switch Conf['Index Mode']
|
switch Conf['Index Mode']
|
||||||
@ -601,8 +599,9 @@ Index =
|
|||||||
Index.pageNav Index.getMaxPageNum()
|
Index.pageNav Index.getMaxPageNum()
|
||||||
return
|
return
|
||||||
threadsPerPage = Index.getThreadsNumPerPage()
|
threadsPerPage = Index.getThreadsNumPerPage()
|
||||||
nodes = Index.sortedNodes[threadsPerPage * pageNum ... threadsPerPage * (pageNum + 1)]
|
threads = Index.sortedThreads[threadsPerPage * pageNum ... threadsPerPage * (pageNum + 1)]
|
||||||
Index.buildReplies nodes
|
nodes = threads.map (thread) -> thread.OP.nodes.root.parentNode
|
||||||
|
Index.buildReplies threads
|
||||||
Index.buildHRs nodes
|
Index.buildHRs nodes
|
||||||
Index.buildPagelist()
|
Index.buildPagelist()
|
||||||
Index.setPage()
|
Index.setPage()
|
||||||
@ -610,8 +609,8 @@ Index =
|
|||||||
nodes = Index.buildCatalogViews()
|
nodes = Index.buildCatalogViews()
|
||||||
Index.sizeCatalogViews nodes
|
Index.sizeCatalogViews nodes
|
||||||
else
|
else
|
||||||
nodes = [Index.sortedNodes...]
|
nodes = Index.sortedThreads.map (thread) -> thread.OP.nodes.root.parentNode
|
||||||
Index.buildReplies nodes
|
Index.buildReplies Index.sortedThreads
|
||||||
Index.buildHRs nodes
|
Index.buildHRs nodes
|
||||||
$.rmAll Index.root
|
$.rmAll Index.root
|
||||||
$.add Index.root, nodes
|
$.add Index.root, nodes
|
||||||
@ -650,8 +649,8 @@ Index =
|
|||||||
return unless keywords = query.toLowerCase().match /\S+/g
|
return unless keywords = query.toLowerCase().match /\S+/g
|
||||||
Index.search keywords
|
Index.search keywords
|
||||||
search: (keywords) ->
|
search: (keywords) ->
|
||||||
Index.sortedNodes.filter (threadRoot) ->
|
Index.sortedThreads.filter (thread) ->
|
||||||
Index.searchMatch Get.threadFromRoot(threadRoot), keywords
|
Index.searchMatch thread, keywords
|
||||||
searchMatch: (thread, keywords) ->
|
searchMatch: (thread, keywords) ->
|
||||||
{info, file} = thread.OP
|
{info, file} = thread.OP
|
||||||
text = []
|
text = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user