mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 23:23:52 +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)
|
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)
|
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)
|
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 $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;
|
namespace Flarum\Api\Serializer;
|
||||||
|
|
||||||
use Flarum\Core\Post;
|
use Flarum\Core\Post;
|
||||||
|
use Flarum\Core\Post\CommentPost;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class PostBasicSerializer extends AbstractSerializer
|
class PostBasicSerializer extends AbstractSerializer
|
||||||
|
@ -42,6 +43,12 @@ class PostBasicSerializer extends AbstractSerializer
|
||||||
'contentType' => $post->type
|
'contentType' => $post->type
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($post instanceof CommentPost) {
|
||||||
|
$attributes['contentHtml'] = $post->content_html;
|
||||||
|
} else {
|
||||||
|
$attributes['content'] = $post->content;
|
||||||
|
}
|
||||||
|
|
||||||
return $attributes;
|
return $attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user