mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 15:03:44 +08:00
Performance: Load only basic information about terminal/relevant posts
This commit is contained in:
parent
89a43d1adf
commit
a4849355aa
|
@ -54,7 +54,7 @@ class DiscussionBasicSerializer extends AbstractSerializer
|
|||
*/
|
||||
protected function startPost($discussion)
|
||||
{
|
||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\PostSerializer');
|
||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\PostBasicSerializer');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,7 @@ class DiscussionBasicSerializer extends AbstractSerializer
|
|||
*/
|
||||
protected function lastPost($discussion)
|
||||
{
|
||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\PostSerializer');
|
||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\PostBasicSerializer');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,6 +86,14 @@ class DiscussionBasicSerializer extends AbstractSerializer
|
|||
*/
|
||||
protected function relevantPosts($discussion)
|
||||
{
|
||||
return $this->hasMany($discussion, 'Flarum\Api\Serializer\PostSerializer');
|
||||
return $this->hasMany($discussion, 'Flarum\Api\Serializer\PostBasicSerializer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Tobscure\JsonApi\Relationship
|
||||
*/
|
||||
protected function hideUser($discussion)
|
||||
{
|
||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\UserBasicSerializer');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,12 +64,4 @@ class DiscussionSerializer extends DiscussionBasicSerializer
|
|||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Tobscure\JsonApi\Relationship
|
||||
*/
|
||||
protected function hideUser($discussion)
|
||||
{
|
||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\UserSerializer');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Flarum\Api\Serializer;
|
||||
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Core\Post\CommentPost;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class PostBasicSerializer extends AbstractSerializer
|
||||
|
@ -42,6 +43,12 @@ class PostBasicSerializer extends AbstractSerializer
|
|||
'contentType' => $post->type
|
||||
];
|
||||
|
||||
if ($post instanceof CommentPost) {
|
||||
$attributes['contentHtml'] = $post->content_html;
|
||||
} else {
|
||||
$attributes['content'] = $post->content;
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user