mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 11:02:46 +08:00
PERF: Don't include entire post stream when we're loading more posts.
This commit is contained in:
parent
657c8a013a
commit
bad6a5142c
|
@ -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)));
|
||||
}
|
||||
|
|
|
@ -3,14 +3,18 @@ require_dependency 'post_serializer'
|
|||
require_dependency 'timeline_lookup'
|
||||
|
||||
module PostStreamSerializerMixin
|
||||
|
||||
def self.included(klass)
|
||||
klass.attributes :post_stream
|
||||
klass.attributes :timeline_lookup
|
||||
end
|
||||
|
||||
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?
|
||||
result
|
||||
end
|
||||
|
|
|
@ -8,4 +8,12 @@ class TopicViewPostsSerializer < ApplicationSerializer
|
|||
object.topic.id
|
||||
end
|
||||
|
||||
def include_stream?
|
||||
false
|
||||
end
|
||||
|
||||
def include_timeline_lookup?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
|
|
26
spec/serializers/topic_view_posts_serializer_spec.rb
Normal file
26
spec/serializers/topic_view_posts_serializer_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in New Issue
Block a user