-
-
Notifications
You must be signed in to change notification settings - Fork 835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tags performance issue Forum::tags #2177
Comments
This PR: flarum/tags#84 should already reduce strain substantially. From there:
|
After migrating tags from the old forum to Flarum, I wondered why the forum was loading indefinitely. Well, we have the answer - I have 2000+ tags 😄 I like the first solution:
|
@rafaucau we're now investigating another possible cause: by any chance, do you have the fof follow tags extension installed? |
@askvortsov1 Yes |
Then that's likely it: an issue with FoF follow tags means that multiple SQL queries are made per tag whenever loading a page. I'm gonna close this for now unless someone can reproduce this on an install with only core extensions. |
@askvortsov1 After disabling FoF follow-tags I don't see any difference. It still loads very slowly |
Nevermind then... Could you open a new issue and share the output of your |
The problem is generated in TagSerializer by:
and
|
@simon1222 is this something you've confirmed via testing? We were able to determine that disabling FoF Follow Tags reduces the number of SQL queries sent to the database on initial load from 411 to 54 for a forum with hundreds of tags. |
@askvortsov1 yes, I've confimed via testing. I have 320k discussions and 2k tags, so lastPostedDiscussion was one of the problem. I was waiting about 60s, so I've commented
but methods, which are executed in Serializer, are working too slow. I think these methods generate too many queries to the database. |
hmm, thing is, that should be processed by the includes system, which would load it all in one query. It would be super helpful to get a bit more information as to what is going on with your forum, so we can try to fix some of these bugs and increase performance. Would you be able to use https://github.com/FriendsOfFlarum/clockwork (if it works) or some alternate tool to see how many and which database requests are being made on forum load? Also, could you share the URL of your forum and the output of |
I think big performance gains will be achieved by not loading the lastPostedDiscussion relationship on normal pages. I might be wrong, but I think it's only used on the tags overview page. Here's the relevant code: /**
* @param WillGetData $event
*/
public function includeTagsRelationship(WillGetData $event)
{
if ($event->isController(ShowForumController::class)) {
$event->addInclude(['tags', 'tags.lastPostedDiscussion', 'tags.parent']);
}
} That would remove two SQL queries per Tag: SELECT * FROM `discussions` WHERE `discussions`.`id` = '1' LIMIT | runtime: 0.27 ms
SELECT `tags`.*, `discussion_tag`.`discussion_id` as `pivot_discussion_id`, `discussion_tag`.`tag_id` as `pivot_tag_id` FROM `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` WHERE `discussion_tag`.`discussion_id` = '1' | runtime: 0.43 ms And it would also remove the size of the payload JSON significantly. Right now every last posted discussion object is included in the resource section. |
@w-4 That's a good point. The last posted discussion can be loaded through an HTTP request when one clicks the tags page and/or included only in the /tags route. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep the amount of open issues to a manageable minimum. |
Sharing what I recently found, So I decided to update Simply eager loading these relationships solves the issue by only using two queries instead of two queries per primary tag. Do we want to make this change or instead just do as posted above and query the lastPostedDiscussions from the frontend while also limiting the number of tags exposed ? We could include this fix for now since it doesn't hurt. (I posted the PR incase we'd like to do that). $data['tags'] = Tag::whereVisibleTo($actor)
->withStateFor($actor)
->with([
'parent',
'lastPostedDiscussion',
'lastPostedDiscussion.tags',
'lastPostedDiscussion.state'
])
->get(); Also observation here, we don't actually need to eager load the tags here since we are loading all of them, we could just loop through all the |
I'd be in favor of including this since those queries are needed anyway, but I wouldn't close this issue until we properly paginate it and only load the tags we need, when we need them. |
Infinite nesting PR might have a start to this |
Plan for handling this is to do it in 3 stages. Stage 1: only load top-level primary tags, top 3 secondary tags, and current tag's children/siblings on an arbitrary forum request. This solves the issue of thousands of tags being loaded in at once, which understandably makes things very slow. This is ready for review at flarum/tags#87 Stage 2: Optimize tag permission checking so we don't have to send huge arrays to/from the database. This significantly speeds up all pages (2x at least), and when coupled with Stage 1, makes the effect of tags negligible for every page except the "Tags" page. This is ready for review at flarum/tags#126 Stage 3: Pagination. I propose the following changes:
Stages 1 and 2 make tags usable on an enterprise-scale forum. Stage 3 enables hundreds of primary and thousands of secondary tags with elegant scaling. Stage 3 will likely be after stable. |
Bug Report
Current Behavior
https://github.com/flarum/tags/blob/fa83f496b0004e31ef2f4fc854bfcdf6a4cfa3c3/src/Listener/AddForumTagsRelationship.php#L46-L58
This piece of code is responsible for a performance penalty with forums that have many tags. There are a few things at fault here:
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.Suggested solution
What needs to be done is:
or:
Environment
The text was updated successfully, but these errors were encountered: