mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 19:00:32 -06:00
FIX: Sometimes the total post count could be incorrect
This commit is contained in:
parent
19f3a8d640
commit
3761ccb018
@ -359,7 +359,7 @@ Discourse.PostStream = Em.Object.extend({
|
||||
**/
|
||||
commitPost: function(post) {
|
||||
this.appendPost(post);
|
||||
this.get('stream').pushObject(post.get('id'));
|
||||
this.get('stream').addObject(post.get('id'));
|
||||
this.set('stagingPost', false);
|
||||
},
|
||||
|
||||
@ -435,7 +435,7 @@ Discourse.PostStream = Em.Object.extend({
|
||||
var lastPostLoaded = this.get('lastPostLoaded');
|
||||
|
||||
if (this.get('stream').indexOf(postId) === -1) {
|
||||
this.get('stream').pushObject(postId);
|
||||
this.get('stream').addObject(postId);
|
||||
if (lastPostLoaded) { this.appendMore(); }
|
||||
}
|
||||
},
|
||||
@ -602,6 +602,7 @@ Discourse.PostStream = Em.Object.extend({
|
||||
return this.get('stream').indexOf(post.get('id'));
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
@private
|
||||
|
||||
|
@ -312,7 +312,6 @@ test("staging and committing a post", function() {
|
||||
|
||||
});
|
||||
|
||||
|
||||
test('triggerNewPostInStream', function() {
|
||||
var postStream = buildStream(225566);
|
||||
|
||||
@ -341,3 +340,22 @@ test('triggerNewPostInStream', function() {
|
||||
ok(postStream.appendMore.calledOnce, "delegates to appendMore because the last post is loaded");
|
||||
});
|
||||
|
||||
|
||||
test("comitting and triggerNewPostInStream race condition", function() {
|
||||
var postStream = buildStream(4964);
|
||||
|
||||
postStream.appendPost(Discourse.Post.create({id: 1, post_number: 1}));
|
||||
var user = Discourse.User.create({username: 'eviltrout', name: 'eviltrout', id: 321});
|
||||
var stagedPost = Discourse.Post.create({ raw: 'hello world this is my new post' });
|
||||
|
||||
var result = postStream.stagePost(stagedPost, user);
|
||||
equal(postStream.get('filteredPostsCount'), 0, "it has no filteredPostsCount yet");
|
||||
stagedPost.set('id', 123);
|
||||
|
||||
this.stub(postStream, 'appendMore');
|
||||
postStream.triggerNewPostInStream(123);
|
||||
equal(postStream.get('filteredPostsCount'), 1, "it added the post");
|
||||
|
||||
postStream.commitPost(stagedPost);
|
||||
equal(postStream.get('filteredPostsCount'), 1, "it does not add the same post twice");
|
||||
});
|
Loading…
Reference in New Issue
Block a user