-
-
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
Eagerload some needed relations in ListDiscussionsController #2639
Conversation
@@ -110,9 +110,13 @@ protected function data(ServerRequestInterface $request, Document $document) | |||
|
|||
Discussion::setStateUser($actor); | |||
|
|||
if (in_array('mostRelevantPost.user', $include)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a comment saying this is done for eager loading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to explain why we need to eager load it or just state that we're eager loading it ?
Observation: this is currently only necessary because the suspend extension's UserPolicy calls isAdmin
on the $user
object which loads all groups, in which case we should be eager loading the relation in the extension and not here, but I'm seeing in https://github.com/flarum/core/pull/2620/files#diff-5f5aff0db193a1b7b5bdff796982aefe84572973059c31c65f33233e7fafd597R34-R36 that we might end up doing it in core as well, so it will belong here after all (if that pr isn't changed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the comment reflect that? Suggestion:
// Eager load groups for use in the policies (isAdmin check)
36f855b
to
b5c63ab
Compare
b5c63ab
to
f32b471
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to try it locally. But here's a reply on the existing comments
@@ -110,9 +110,13 @@ protected function data(ServerRequestInterface $request, Document $document) | |||
|
|||
Discussion::setStateUser($actor); | |||
|
|||
if (in_array('mostRelevantPost.user', $include)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the comment reflect that? Suggestion:
// Eager load groups for use in the policies (isAdmin check)
22f6354
to
885f454
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested the earlier version locally. Final version looks good code-wise
Part Of #2637
Changes proposed in this pull request:
Ensures some needed relations are present/eagerloded.
Can be tested by going to
/api/discussions?filter[q]=ipsum
Screenshot
⬇️
Confirmed
composer test
).