From faaf8a8c0014e44699ef09de793e564100d952d8 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 19 Jul 2011 00:53:00 +0200 Subject: [PATCH] Fix Thread Stats slowdown; use querySelector once. --- 4chan_x.user.js | 10 +++++----- changelog | 1 + script.coffee | 10 +++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 971aad936..08c0b61d7 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2275,6 +2275,8 @@ left: '0px' }, html); dialog.className = 'dialog'; + threadStats.postcountID = $('#postcount', dialog); + threadStats.imagecountID = $('#imagecount', dialog); $.append(d.body, dialog); return g.callbacks.push(threadStats.node); }, @@ -2282,15 +2284,13 @@ if (root.className) { return; } - threadStats.posts++; + threadStats.postcountID.textContent = ++threadStats.posts; if ($('img[md5]', root)) { - threadStats.images++; + threadStats.imagecountID.textContent = ++threadStats.images; if (threadStats.images > 150) { - $('#imagecount').className = 'error'; + return threadStats.imagecountID.className = 'error'; } } - $('#postcount').textContent = threadStats.posts; - return $('#imagecount').textContent = threadStats.images; } }; unread = { diff --git a/changelog b/changelog index 1f0654418..a0a82341c 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ - mayhem: - Fix Auto Watch Reply and prevent upload of too large files when auto posting + - Thread Stats performance fix, especially on long threads 2.15.1 - mayhem: diff --git a/script.coffee b/script.coffee index 9517ac01f..6ab1d836b 100644 --- a/script.coffee +++ b/script.coffee @@ -1746,17 +1746,17 @@ threadStats = html = "
#{threadStats.posts} / #{threadStats.images}
" dialog = ui.dialog 'stats', bottom: '0px', left: '0px', html dialog.className = 'dialog' + threadStats.postcountID = $ '#postcount', dialog + threadStats.imagecountID = $ '#imagecount', dialog $.append d.body, dialog g.callbacks.push threadStats.node node: (root) -> return if root.className - threadStats.posts++ + threadStats.postcountID.textContent = ++threadStats.posts if $ 'img[md5]', root - threadStats.images++ + threadStats.imagecountID.textContent = ++threadStats.images if threadStats.images > 150 - $('#imagecount').className = 'error' - $('#postcount').textContent = threadStats.posts - $('#imagecount').textContent = threadStats.images + threadStats.imagecountID.className = 'error' unread = init: ->