-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
N+1 Queries #2637
Comments
I'm not sure of the use case for passing in The I find the notifications one to be a little bit less of a priority (which is great since it's the hardest one 😆), I'll need to look into the code a bit more before opining on it. |
The DiscussionSerializer checks for abilities, which are routed to the tags extension's DicussionPolicy, which uses tag scopes, thus requiring the tags relationship. We could right now avoid a query for the
Certainly. |
Some more on this: The Possible Solutions:
|
I'm closing this, if the future we'll have separate issues for these problems. Notifications endpoint N+1 Queries issue has been split off to: flarum/issue-archive#113 |
Somewhat related to #2177
We currently have a problem with N+1 queries, some endpoints have certain relationships eager loaded, but not others, because they are either not needed by the frontend yet still called in certain serializers, or needed but just not eager loaded.
I have found these endpoints so far with this issue.
mostRelevantPost
(Eagerload some needed relations in ListDiscussionsController #2639)tags
(Eager load tags relation in discussion, posts and flags listing endpoints tags#125)discussion
(Eager load ListPostsController needed relations #2717)discussion.tags
(Eager load tags relation in discussion, posts and flags listing endpoints tags#125)user.groups
(Eager load ListPostsController needed relations #2717)mentionedBy
(Eager load mentionedBy and only missing relations mentions#64)post.discussion.tags
(Eager load tags relation in discussion, posts and flags listing endpoints tags#125)post.user.groups
(Eager load post.user.groups relation and allow extensions to eager load relations flags#38)Tags - ShowForumController (flarum/tags#120)
Relations:
lastPostedDiscussion
(lastPostedDiscussion.state
,lastPostedDiscussion.tags
)In flarum/tags#120 I decided to eager load the two relations used to fix the problem, but looking at it again, we really shouldn't have to do that, the TagsPage component only needs three things from the lastPostedDiscussion: title, lastPostNumber, lastPostedAt. All of which are basic information.
Could we either add that data to BasicDiscussionSerializer and use that instead of DiscussionSerializer, or create a custom DiscussionSerializer in the tags extension, exposing only the information we need, that would be cleaner than eager loading relations just because the default serializer assumes they're available.
Search - ListDiscussionsController (#2639)
Relations:
mostRelevantPost
(mostRelevantPost.discussion
,mostRelevantPost.discussion.tags
,mostRelevantPost.user.groups
)This one should be rather simple, this is what we currently do for the
firstPost
andlastPost
relations, we can just apply the same logic to themostRelevantPost
relation.https://github.com/flarum/core/blob/023871ef86d436cc14631ee63cbbfd3ef9fd4bf1/src/Api/Controller/ListDiscussionsController.php#L115-L123
Posts - ListPostsController
Relations:
user.groups
,discussion
&discussion.tags
(only when flags is enabled),mentionedBy
(only when mentions is enabled)This is a case scenario where some kind of
loadRelations
extender onApiController
would solve the problem (read #2637 (comment))Notifications - ListNotificationsController
Relations:
subject.discussion
(subject.discussion.tags
) andsubject.???
(subject.???.???
)This one may or may not be more complicated. When subjects are related to discussions, those discussions need tags loaded for ability checks: are they even necessary here ? no. But we do need sticky, locked, and follow data which are only exposed in the DiscussionSerializer.
Another thing is, depending on what the type is, there might be N+1 queries. I've found that
postMentioned
types needmentionsUsers
relation loaded because it evaluates the content of the post, but I am not sure yet about other types.Flags - ListFlagsController
Relations:
post.user.groups
post.discussion.tags
First one is simple, for the second one I'm not sure in which extension we want to eager load the relation.
The text was updated successfully, but these errors were encountered: