mirror of
https://github.com/flarum/framework.git
synced 2024-11-29 04:33:47 +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 Flarum\Tags\Tag;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
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 [
|
return [
|
||||||
(new Extend\Frontend('forum'))
|
(new Extend\Frontend('forum'))
|
||||||
->js(__DIR__.'/js/dist/forum.js')
|
->js(__DIR__.'/js/dist/forum.js')
|
||||||
|
@ -73,17 +79,15 @@ return [
|
||||||
|
|
||||||
(new Extend\ApiController(FlarumController\ListDiscussionsController::class))
|
(new Extend\ApiController(FlarumController\ListDiscussionsController::class))
|
||||||
->addInclude(['tags', 'tags.state', 'tags.parent'])
|
->addInclude(['tags', 'tags.state', 'tags.parent'])
|
||||||
->loadWhere('tags', function ($query, ?ServerRequestInterface $request, array $relations) {
|
->loadWhere('tags', $eagerLoadTagState),
|
||||||
if ($request && in_array('tags.state', $relations, true)) {
|
|
||||||
$query->withStateFor(RequestUtil::getActor($request));
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
(new Extend\ApiController(FlarumController\ShowDiscussionController::class))
|
(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))
|
(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))
|
(new Extend\ApiController(FlarumController\ShowForumController::class))
|
||||||
->addInclude(['tags', 'tags.parent'])
|
->addInclude(['tags', 'tags.parent'])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user