Skip to content
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

Merged
merged 5 commits into from
Mar 7, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a comment about eager loading
  • Loading branch information
SychO9 committed Mar 7, 2021
commit 29359e3a0a51ee8d6173108fea72232a9c986e7d
1 change: 1 addition & 0 deletions src/Api/Controller/ListDiscussionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ protected function data(ServerRequestInterface $request, Document $document)

Discussion::setStateUser($actor);

// Needed for eager loading
if (in_array('mostRelevantPost.user', $include)) {
Copy link
Member

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

Copy link
Member Author

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).

Copy link
Member

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)

$include[] = 'mostRelevantPost.user.groups';
}
Expand Down