Browse Source

optimize attachPostsToStream()

readme-update
Simon Grim 9 years ago
parent
commit
8feb66bc72
  1. 10
      js/twister_timeline.js

10
js/twister_timeline.js

@ -192,9 +192,6 @@ function updateTimeline(req, posts) { @@ -192,9 +192,6 @@ function updateTimeline(req, posts) {
function attachPostsToStream(stream, posts, isPromoted) {
//console.log('attachPostsToStream:');
//console.log(posts);
function byTimeInDescendingOrder(a, b) {
return (a.time > b.time) ? -1 : 1;
}
var streamItems = stream.children();
var streamPosts = [];
@ -203,7 +200,6 @@ function attachPostsToStream(stream, posts, isPromoted) { @@ -203,7 +200,6 @@ function attachPostsToStream(stream, posts, isPromoted) {
var streamItem = streamItems.eq(i);
streamPosts.push({item: streamItem, time: parseInt(streamItem.attr('data-time'))});
}
//streamPosts.sort(byTimeInDescendingOrder); // currently here is no reason to sort it, it should be ok
for (var i = 0; i < posts.length; i++) {
//console.log(posts[i]);
@ -222,8 +218,7 @@ function attachPostsToStream(stream, posts, isPromoted) { @@ -222,8 +218,7 @@ function attachPostsToStream(stream, posts, isPromoted) {
} else if (intrantPost.time > streamPosts[j].time) {
// this post in stream is older, so post must be inserted above
intrantPost.item.insertBefore(streamPosts[j].item).show();
streamPosts.push(intrantPost);
streamPosts.sort(byTimeInDescendingOrder);
streamPosts.splice(j, 0, intrantPost);
isAttached = true;
break;
}
@ -231,8 +226,7 @@ function attachPostsToStream(stream, posts, isPromoted) { @@ -231,8 +226,7 @@ function attachPostsToStream(stream, posts, isPromoted) {
}
if (!isAttached) {
intrantPost.item.appendTo(stream).show();
streamPosts.push(intrantPost);
streamPosts.sort(byTimeInDescendingOrder);
streamPosts.unshift(intrantPost);
}
}
}

Loading…
Cancel
Save