Optimize the index by dealing with HRs as little as possible.
This commit is contained in:
parent
61510ca272
commit
d052bfc186
@ -243,21 +243,23 @@ Build =
|
|||||||
Build.spoilerRange[board] = data.custom_spoiler
|
Build.spoilerRange[board] = data.custom_spoiler
|
||||||
|
|
||||||
if (OP = board.posts[data.no]) and root = OP.nodes.root.parentNode
|
if (OP = board.posts[data.no]) and root = OP.nodes.root.parentNode
|
||||||
$.rmAll root
|
for node in $$ '.thread > :not(.stub):not(.opContainer)', root
|
||||||
|
$.rm node
|
||||||
|
if OP.thread.stub and stub = OP.thread.stub.firstElementChild.lastChild
|
||||||
|
stub.textContent = stub.textContent.replace /\d+ rep\w+/, "#{data.replies} repl#{if data.replies is 1 then 'y' else 'ies'}"
|
||||||
else
|
else
|
||||||
root = $.el 'div',
|
root = $.el 'div',
|
||||||
className: 'thread'
|
className: 'thread'
|
||||||
id: "t#{data.no}"
|
id: "t#{data.no}"
|
||||||
|
$.add root, Build.postFromObject data, board.ID
|
||||||
|
|
||||||
nodes = [if OP then OP.nodes.root else Build.postFromObject data, board.ID]
|
|
||||||
if data.omitted_posts or !Conf['Show Replies'] and data.replies
|
if data.omitted_posts or !Conf['Show Replies'] and data.replies
|
||||||
[posts, files] = if Conf['Show Replies']
|
[posts, files] = if Conf['Show Replies']
|
||||||
[data.omitted_posts, data.omitted_images]
|
[data.omitted_posts, data.omitted_images]
|
||||||
else
|
else
|
||||||
[data.replies, data.images]
|
[data.replies, data.images]
|
||||||
nodes.push Build.summary board.ID, data.no, posts, files
|
$.add root, Build.summary board.ID, data.no, posts, files
|
||||||
|
|
||||||
$.add root, nodes
|
|
||||||
root
|
root
|
||||||
catalogThread: (thread) ->
|
catalogThread: (thread) ->
|
||||||
{staticPath, gifIcon} = Build
|
{staticPath, gifIcon} = Build
|
||||||
|
|||||||
@ -521,7 +521,7 @@ Index =
|
|||||||
posts = []
|
posts = []
|
||||||
for threadData, i in Index.liveThreadData
|
for threadData, i in Index.liveThreadData
|
||||||
threadRoot = Build.thread g.BOARD, threadData
|
threadRoot = Build.thread g.BOARD, threadData
|
||||||
Index.nodes.push threadRoot, $.el 'hr'
|
Index.nodes.push threadRoot
|
||||||
if thread = g.BOARD.threads[threadData.no]
|
if thread = g.BOARD.threads[threadData.no]
|
||||||
thread.setPage i // Index.threadsNumPerPage
|
thread.setPage i // Index.threadsNumPerPage
|
||||||
thread.setCount 'post', threadData.replies + 1, threadData.bumplimit
|
thread.setCount 'post', threadData.replies + 1, threadData.bumplimit
|
||||||
@ -542,15 +542,18 @@ Index =
|
|||||||
error: err
|
error: err
|
||||||
Main.handleErrors errors if errors
|
Main.handleErrors errors if errors
|
||||||
|
|
||||||
# Add the threads and <hr>s in a container to make sure all features work.
|
|
||||||
$.nodes Index.nodes
|
|
||||||
Main.callbackNodes Thread, threads
|
Main.callbackNodes Thread, threads
|
||||||
Main.callbackNodes Post, posts
|
Main.callbackNodes Post, posts
|
||||||
Index.updateHideLabel()
|
Index.updateHideLabel()
|
||||||
$.event 'IndexRefresh'
|
$.event 'IndexRefresh'
|
||||||
|
buildHRs: (threadRoots) ->
|
||||||
|
for i in [0...threadRoots.length] by 1
|
||||||
|
threadRoots.splice (i * 2) + 1, 0, $.el 'hr'
|
||||||
|
return
|
||||||
buildReplies: (threadRoots) ->
|
buildReplies: (threadRoots) ->
|
||||||
|
return unless Conf['Show Replies']
|
||||||
posts = []
|
posts = []
|
||||||
for threadRoot in threadRoots by 2
|
for threadRoot in threadRoots
|
||||||
thread = Get.threadFromRoot threadRoot
|
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
|
||||||
@ -574,7 +577,6 @@ Index =
|
|||||||
Main.callbackNodes Post, posts
|
Main.callbackNodes Post, posts
|
||||||
buildCatalogViews: ->
|
buildCatalogViews: ->
|
||||||
threads = Index.sortedNodes
|
threads = Index.sortedNodes
|
||||||
.filter (n, i) -> !(i % 2)
|
|
||||||
.map (threadRoot) -> Get.threadFromRoot threadRoot
|
.map (threadRoot) -> Get.threadFromRoot threadRoot
|
||||||
.filter (thread) -> !thread.isHidden isnt Index.showHiddenThreads
|
.filter (thread) -> !thread.isHidden isnt Index.showHiddenThreads
|
||||||
catalogThreads = []
|
catalogThreads = []
|
||||||
@ -609,10 +611,8 @@ 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 = []
|
Index.sortedNodes = sortedThreadIDs.map (threadID) ->
|
||||||
for threadID in sortedThreadIDs
|
Index.nodes[Index.liveThreadIDs.indexOf threadID]
|
||||||
i = Index.liveThreadIDs.indexOf(threadID) * 2
|
|
||||||
Index.sortedNodes.push Index.nodes[i], Index.nodes[i + 1]
|
|
||||||
if Index.isSearching
|
if Index.isSearching
|
||||||
Index.sortedNodes = Index.querySearch(Index.searchInput.value) or Index.sortedNodes
|
Index.sortedNodes = Index.querySearch(Index.searchInput.value) or Index.sortedNodes
|
||||||
# Sticky threads
|
# Sticky threads
|
||||||
@ -623,22 +623,25 @@ Index =
|
|||||||
Index.sortOnTop((thread) -> !thread.isHidden) if Conf['Anchor Hidden Threads']
|
Index.sortOnTop((thread) -> !thread.isHidden) if Conf['Anchor Hidden Threads']
|
||||||
sortOnTop: (match) ->
|
sortOnTop: (match) ->
|
||||||
offset = 0
|
offset = 0
|
||||||
for threadRoot, i in Index.sortedNodes by 2 when match Get.threadFromRoot threadRoot
|
for threadRoot, i in Index.sortedNodes when match Get.threadFromRoot threadRoot
|
||||||
Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)...
|
Index.sortedNodes.splice offset++, 0, Index.sortedNodes.splice(i, 1)[0]
|
||||||
return
|
return
|
||||||
buildIndex: ->
|
buildIndex: ->
|
||||||
switch Conf['Index Mode']
|
switch Conf['Index Mode']
|
||||||
when 'paged'
|
when 'paged'
|
||||||
pageNum = Index.getCurrentPage()
|
pageNum = Index.getCurrentPage()
|
||||||
nodesPerPage = Index.getThreadsNumPerPage() * 2
|
threadsPerPage = Index.getThreadsNumPerPage()
|
||||||
nodes = Index.sortedNodes[nodesPerPage * pageNum ... nodesPerPage * (pageNum + 1)]
|
nodes = Index.sortedNodes[threadsPerPage * pageNum ... threadsPerPage * (pageNum + 1)]
|
||||||
|
Index.buildReplies nodes
|
||||||
|
Index.buildHRs nodes
|
||||||
when 'catalog'
|
when 'catalog'
|
||||||
nodes = Index.buildCatalogViews()
|
nodes = Index.buildCatalogViews()
|
||||||
Index.sizeCatalogViews nodes
|
Index.sizeCatalogViews nodes
|
||||||
else
|
else
|
||||||
nodes = Index.sortedNodes
|
nodes = [Index.sortedNodes...]
|
||||||
|
Index.buildReplies nodes
|
||||||
|
Index.buildHRs nodes
|
||||||
$.rmAll Index.root
|
$.rmAll Index.root
|
||||||
Index.buildReplies nodes if Conf['Show Replies'] and Conf['Index Mode'] isnt 'catalog'
|
|
||||||
$.add Index.root, nodes
|
$.add Index.root, nodes
|
||||||
$.event 'IndexBuild', nodes
|
$.event 'IndexBuild', nodes
|
||||||
|
|
||||||
@ -678,11 +681,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) ->
|
||||||
found = []
|
Index.sortedNodes.filter (threadRoot) ->
|
||||||
for threadRoot, i in Index.sortedNodes by 2
|
Index.searchMatch Get.threadFromRoot(threadRoot), keywords
|
||||||
if Index.searchMatch Get.threadFromRoot(threadRoot), keywords
|
|
||||||
found.push Index.sortedNodes[i], Index.sortedNodes[i + 1]
|
|
||||||
found
|
|
||||||
searchMatch: (thread, keywords) ->
|
searchMatch: (thread, keywords) ->
|
||||||
{info, file} = thread.OP
|
{info, file} = thread.OP
|
||||||
text = []
|
text = []
|
||||||
|
|||||||
@ -173,7 +173,7 @@ class Post
|
|||||||
postInfo = if Conf['Anonymize']
|
postInfo = if Conf['Anonymize']
|
||||||
'Anonymous'
|
'Anonymous'
|
||||||
else
|
else
|
||||||
$('.nameBlock', @nodes.info).textContent
|
$('.nameBlock', @nodes.info).textContent.trim()
|
||||||
$.add a, $.tn " #{postInfo}"
|
$.add a, $.tn " #{postInfo}"
|
||||||
@nodes.stub = $.el 'div',
|
@nodes.stub = $.el 'div',
|
||||||
className: 'stub'
|
className: 'stub'
|
||||||
|
|||||||
@ -77,7 +77,7 @@ class Thread
|
|||||||
opInfo = if Conf['Anonymize']
|
opInfo = if Conf['Anonymize']
|
||||||
'Anonymous'
|
'Anonymous'
|
||||||
else
|
else
|
||||||
$('.nameBlock', @OP.nodes.info).textContent
|
$('.nameBlock', @OP.nodes.info).textContent.trim()
|
||||||
|
|
||||||
a = PostHiding.makeButton false
|
a = PostHiding.makeButton false
|
||||||
$.add a, $.tn " #{opInfo} (#{numReplies} repl#{if numReplies is 1 then 'y' else 'ies'})"
|
$.add a, $.tn " #{opInfo} (#{numReplies} repl#{if numReplies is 1 then 'y' else 'ies'})"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user