-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial tag load performance improvement (#87)
- Only load lastPostedDiscussion on TagsPage - For forum payload, only load top-level primary tags and top 3 secondary tags. - In other cases, load tags in dynamically when needed. Co-authored-by: Alexander Skvortsov <[email protected]> Co-authored-by: Sami Mazouz <[email protected]>
- Loading branch information
1 parent
8d07dec
commit c7d8150
Showing
17 changed files
with
257 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export default class TagListState { | ||
constructor() { | ||
this.loadedIncludes = new Set(); | ||
} | ||
|
||
async load(includes = []) { | ||
const unloadedIncludes = includes.filter(include => !this.loadedIncludes.has(include)); | ||
|
||
if (unloadedIncludes.length === 0) { | ||
return Promise.resolve(app.store.all('tags')); | ||
} | ||
|
||
return app.store | ||
.find('tags', { include: 'parent,lastPostedDiscussion' }) | ||
.then(val => { | ||
unloadedIncludes.forEach(include => this.loadedIncludes.add(include)); | ||
return val; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Tags\Api\Controller; | ||
|
||
use Flarum\Api\Controller\AbstractShowController; | ||
use Flarum\Tags\Api\Serializer\TagSerializer; | ||
use Flarum\Tags\Tag; | ||
use Illuminate\Support\Arr; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Tobscure\JsonApi\Document; | ||
|
||
class ShowTagController extends AbstractShowController | ||
{ | ||
public $serializer = TagSerializer::class; | ||
|
||
public $optionalInclude = [ | ||
'children', | ||
'children.parent', | ||
'lastPostedDiscussion', | ||
'parent', | ||
'parent.children', | ||
'parent.children.parent', | ||
'state' | ||
]; | ||
|
||
/** | ||
* @var Tag | ||
*/ | ||
private $tags; | ||
|
||
public function __construct(Tag $tags) | ||
{ | ||
$this->tags = $tags; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function data(ServerRequestInterface $request, Document $document) | ||
{ | ||
$slug = Arr::get($request->getQueryParams(), 'slug'); | ||
$actor = $request->getAttribute('actor'); | ||
$include = $this->extractInclude($request); | ||
|
||
return $this->tags | ||
->whereVisibleTo($actor) | ||
->with($include) | ||
->where('slug', $slug) | ||
->firstOrFail(); | ||
} | ||
} |
Oops, something went wrong.