Append all the new posts at once, using a documentFragment. Optimizations.

This commit is contained in:
Nicolas Stepien 2011-12-10 18:52:09 +01:00
parent 816576b573
commit 7dd32aba23
2 changed files with 24 additions and 23 deletions

View File

@ -2012,7 +2012,7 @@
} }
}, },
update: function() { update: function() {
var arr, body, id, input, replies, reply, scroll, _i, _len, _ref, _ref2; var body, frag, id, input, newPosts, reply, scroll, _i, _j, _len, _len2, _ref, _ref2, _ref3;
if (this.status === 404) { if (this.status === 404) {
updater.timer.textContent = ''; updater.timer.textContent = '';
updater.count.textContent = 404; updater.count.textContent = 404;
@ -2038,24 +2038,25 @@
updater.count.className = 'error'; updater.count.className = 'error';
return; return;
} }
replies = $$('.reply', body); id = ((_ref2 = $('td[id]', updater.br.previousElementSibling)) != null ? _ref2.id : void 0) || 0;
id = Number(((_ref2 = $('td[id]', updater.br.previousElementSibling)) != null ? _ref2.id : void 0) || 0); frag = d.createDocumentFragment();
arr = []; _ref3 = $$('.reply', body).reverse();
while ((reply = replies.pop()) && (reply.id > id)) { for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
arr.push(reply.parentNode.parentNode.parentNode); reply = _ref3[_j];
if (reply.id === id) break;
$.prepend(frag, reply.parentNode.parentNode.parentNode);
} }
scroll = conf['Scrolling'] && updater.focus && arr.length && (d.body.scrollHeight - d.body.clientHeight - window.scrollY < 20); newPosts = frag.childNodes.length;
scroll = conf['Scrolling'] && updater.focus && newPosts && (d.body.scrollHeight - d.body.clientHeight - window.scrollY < 20);
if (conf['Verbose']) { if (conf['Verbose']) {
updater.count.textContent = '+' + arr.length; updater.count.textContent = '+' + newPosts;
if (arr.length === 0) { if (newPosts === 0) {
updater.count.className = ''; updater.count.className = '';
} else { } else {
updater.count.className = 'new'; updater.count.className = 'new';
} }
} }
while (reply = arr.pop()) { $.before(updater.br, frag);
$.before(updater.br, reply);
}
if (scroll) return scrollTo(0, d.body.scrollHeight); if (scroll) return scrollTo(0, d.body.scrollHeight);
} }
}, },

View File

@ -1625,23 +1625,23 @@ updater =
updater.count.className = 'error' updater.count.className = 'error'
return return
replies = $$ '.reply', body id = $('td[id]', updater.br.previousElementSibling)?.id or 0
id = Number $('td[id]', updater.br.previousElementSibling)?.id or 0 frag = d.createDocumentFragment()
arr = [] for reply in $$('.reply', body).reverse()
while (reply = replies.pop()) and (reply.id > id) if reply.id is id
arr.push reply.parentNode.parentNode.parentNode #table break
$.prepend frag, reply.parentNode.parentNode.parentNode #table
scroll = conf['Scrolling'] && updater.focus && arr.length && (d.body.scrollHeight - d.body.clientHeight - window.scrollY < 20) newPosts = frag.childNodes.length
scroll = conf['Scrolling'] && updater.focus && newPosts && (d.body.scrollHeight - d.body.clientHeight - window.scrollY < 20)
if conf['Verbose'] if conf['Verbose']
updater.count.textContent = '+' + arr.length updater.count.textContent = '+' + newPosts
if arr.length is 0 if newPosts is 0
updater.count.className = '' updater.count.className = ''
else else
updater.count.className = 'new' updater.count.className = 'new'
#XXX add replies in correct order so backlinks resolve $.before updater.br, frag
while reply = arr.pop()
$.before updater.br, reply
if scroll if scroll
scrollTo 0, d.body.scrollHeight scrollTo 0, d.body.scrollHeight