A platform for community discussion. Free, open, simple.
PERF: Don't include entire post stream when we're loading more posts.
Guo Xiang Tanbad6a5142cd1
diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6index a2a30048314..7b4b27249ea 100644--- a/app/assets/javascripts/discourse/models/post-stream.js.es6+++ b/app/assets/javascripts/discourse/models/post-stream.js.es6@@ -854,13 +854,14 @@ export default RestModel.extend({const url = "/t/" + this.get("topic.id") + "/posts.json";const data = { post_ids: postIds };const store = this.store;- return ajax(url, { data }).then(result => {- const posts = Ember.get(result, "post_stream.posts");+ return ajax(url, { data }).then(result => {if (result.suggested_topics) {this.set("topic.suggested_topics", result.suggested_topics);}+ const posts = Ember.get(result, "post_stream.posts");+if (posts) {posts.forEach(p => this.storePost(store.createRecord("post", p)));}diff --git a/app/serializers/post_stream_serializer_mixin.rb b/app/serializers/post_stream_serializer_mixin.rbindex 26213f059c8..02f9b582cc8 100644--- a/app/serializers/post_stream_serializer_mixin.rb+++ b/app/serializers/post_stream_serializer_mixin.rb@@ -3,14 +3,18 @@ require_dependency 'post_serializer'require_dependency 'timeline_lookup'module PostStreamSerializerMixin-def self.included(klass)klass.attributes :post_streamklass.attributes :timeline_lookupend+ def include_stream?+ true+ end+def post_stream- result = { posts: posts, stream: object.filtered_post_ids }+ result = { posts: posts }+ result[:stream] = object.filtered_post_ids if include_stream?result[:gaps] = GapSerializer.new(object.gaps, root: false) if object.gaps.present?resultenddiff --git a/app/serializers/topic_view_posts_serializer.rb b/app/serializers/topic_view_posts_serializer.rbindex 98c6cabff76..b51acf525f3 100644--- a/app/serializers/topic_view_posts_serializer.rb+++ b/app/serializers/topic_view_posts_serializer.rb@@ -8,4 +8,12 @@ class TopicViewPostsSerializer < ApplicationSerializerobject.topic.idend+ def include_stream?+ false+ end++ def include_timeline_lookup?+ false+ end+enddiff --git a/spec/serializers/topic_view_posts_serializer_spec.rb b/spec/serializers/topic_view_posts_serializer_spec.rbnew file mode 100644index 00000000000..f69b4080645--- /dev/null+++ b/spec/serializers/topic_view_posts_serializer_spec.rb@@ -0,0 +1,26 @@+require 'rails_helper'++RSpec.describe TopicViewPostsSerializer do+ let(:user) { Fabricate(:user) }+ let(:post) { Fabricate(:post) }+ let(:topic) { post.topic }+ let(:topic_view) { TopicView.new(topic, user, post_ids: [post.id]) }++ subject do+ described_class.new(topic_view,+ scope: Guardian.new(Fabricate(:admin)),+ root: false+ )+ end++ it 'should return the right attributes' do+ body = JSON.parse(subject.to_json)++ posts = body["post_stream"]["posts"]++ expect(posts.count).to eq(1)+ expect(posts.first["id"]).to eq(post.id)+ expect(body["post_stream"]["stream"]).to eq(nil)+ expect(body["post_stream"]["timeline_lookup"]).to eq(nil)+ end+end