Performance: Load only basic information about terminal/relevant posts

This commit is contained in:
Toby Zerner 2017-11-11 22:57:41 +10:30
parent 89a43d1adf
commit a4849355aa
3 changed files with 18 additions and 11 deletions

View File

@ -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');
}
}

View File

@ -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');
}
}

View File

@ -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;
}