mirror of
https://github.com/twisterarmy/twister-html.git
synced 2025-03-12 05:21:18 +00:00
optimize attachPostsToStream()
This commit is contained in:
parent
0e26f527f0
commit
8feb66bc72
@ -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) {
|
||||
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) {
|
||||
} 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) {
|
||||
}
|
||||
if (!isAttached) {
|
||||
intrantPost.item.appendTo(stream).show();
|
||||
streamPosts.push(intrantPost);
|
||||
streamPosts.sort(byTimeInDescendingOrder);
|
||||
streamPosts.unshift(intrantPost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user