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() {
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) {
updater.timer.textContent = '';
updater.count.textContent = 404;
@ -2038,24 +2038,25 @@
updater.count.className = 'error';
return;
}
replies = $$('.reply', body);
id = Number(((_ref2 = $('td[id]', updater.br.previousElementSibling)) != null ? _ref2.id : void 0) || 0);
arr = [];
while ((reply = replies.pop()) && (reply.id > id)) {
arr.push(reply.parentNode.parentNode.parentNode);
id = ((_ref2 = $('td[id]', updater.br.previousElementSibling)) != null ? _ref2.id : void 0) || 0;
frag = d.createDocumentFragment();
_ref3 = $$('.reply', body).reverse();
for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
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']) {
updater.count.textContent = '+' + arr.length;
if (arr.length === 0) {
updater.count.textContent = '+' + newPosts;
if (newPosts === 0) {
updater.count.className = '';
} else {
updater.count.className = 'new';
}
}
while (reply = arr.pop()) {
$.before(updater.br, reply);
}
$.before(updater.br, frag);
if (scroll) return scrollTo(0, d.body.scrollHeight);
}
},

View File

@ -1625,23 +1625,23 @@ updater =
updater.count.className = 'error'
return
replies = $$ '.reply', body
id = Number $('td[id]', updater.br.previousElementSibling)?.id or 0
arr = []
while (reply = replies.pop()) and (reply.id > id)
arr.push reply.parentNode.parentNode.parentNode #table
id = $('td[id]', updater.br.previousElementSibling)?.id or 0
frag = d.createDocumentFragment()
for reply in $$('.reply', body).reverse()
if reply.id is id
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']
updater.count.textContent = '+' + arr.length
if arr.length is 0
updater.count.textContent = '+' + newPosts
if newPosts is 0
updater.count.className = ''
else
updater.count.className = 'new'
#XXX add replies in correct order so backlinks resolve
while reply = arr.pop()
$.before updater.br, reply
$.before updater.br, frag
if scroll
scrollTo 0, d.body.scrollHeight