Closed
Description
Bug Report
Current Behavior
public function loadTagsRelationship(WillSerializeData $event)
{
// Expose the complete tag list to clients by adding it as a
// relationship to the /api endpoint. Since the Forum model
// doesn't actually have a tags relationship, we will manually load and
// assign the tags data to it using an event listener.
if ($event->isController(ShowForumController::class)) {
$event->data['tags'] = Tag::whereVisibleTo($event->actor)
->withStateFor($event->actor)
->with(['parent', 'lastPostedDiscussion'])
->get();
}
}
This piece of code is responsible for a performance penalty with forums that have many tags. There are a few things at fault here:
- Loading all tags into the js
app
on load, even though only 5 (?) are initially shown on the side bar and the index can load them through the api as an include. - This specific piece of code seems to cause 2 queries per tag. For a forum with 100+ tags, this boils down to an additional two seconds loading time (first byte that is).
Suggested solution
What needs to be done is:
- Load only those tags on page load that are actually shown on the sidebar
- Load the additional tags on request
- Include the tags in the discussion list request
or:
- Identify and solve the issue with the Relation listener
Environment
- Flarum version: all of them, but tested on beta 13