mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 20:16:08 +08:00
perf: Fix eager loading of tag state relation in other endpoints (#151)
This commit is contained in:
parent
c1069ff035
commit
f7777ff9e3
|
@ -31,6 +31,12 @@ use Flarum\Tags\Query\TagFilterGambit;
|
|||
use Flarum\Tags\Tag;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
$eagerLoadTagState = function ($query, ?ServerRequestInterface $request, array $relations) {
|
||||
if ($request && in_array('tags.state', $relations, true)) {
|
||||
$query->withStateFor(RequestUtil::getActor($request));
|
||||
}
|
||||
};
|
||||
|
||||
return [
|
||||
(new Extend\Frontend('forum'))
|
||||
->js(__DIR__.'/js/dist/forum.js')
|
||||
|
@ -73,17 +79,15 @@ return [
|
|||
|
||||
(new Extend\ApiController(FlarumController\ListDiscussionsController::class))
|
||||
->addInclude(['tags', 'tags.state', 'tags.parent'])
|
||||
->loadWhere('tags', function ($query, ?ServerRequestInterface $request, array $relations) {
|
||||
if ($request && in_array('tags.state', $relations, true)) {
|
||||
$query->withStateFor(RequestUtil::getActor($request));
|
||||
}
|
||||
}),
|
||||
->loadWhere('tags', $eagerLoadTagState),
|
||||
|
||||
(new Extend\ApiController(FlarumController\ShowDiscussionController::class))
|
||||
->addInclude(['tags', 'tags.state', 'tags.parent']),
|
||||
->addInclude(['tags', 'tags.state', 'tags.parent'])
|
||||
->loadWhere('tags', $eagerLoadTagState),
|
||||
|
||||
(new Extend\ApiController(FlarumController\CreateDiscussionController::class))
|
||||
->addInclude(['tags', 'tags.state', 'tags.parent']),
|
||||
->addInclude(['tags', 'tags.state', 'tags.parent'])
|
||||
->loadWhere('tags', $eagerLoadTagState),
|
||||
|
||||
(new Extend\ApiController(FlarumController\ShowForumController::class))
|
||||
->addInclude(['tags', 'tags.parent'])
|
||||
|
|
Loading…
Reference in New Issue
Block a user