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

Conversation

SychO9
Copy link
Member

@SychO9 SychO9 commented Feb 26, 2021

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
Screenshot from 2021-02-26 20-44-16
⬇️
Screenshot from 2021-02-26 20-47-54

Confirmed

  • Backend changes: tests are green (run composer test).

@@ -110,9 +110,13 @@ protected function data(ServerRequestInterface $request, Document $document)

Discussion::setStateUser($actor);

if (in_array('mostRelevantPost.user', $include)) {
Copy link
Sponsor 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)

@SychO9 SychO9 force-pushed the sm/2637-list-discussions-eagerloading branch from 36f855b to b5c63ab Compare March 3, 2021 14:16
@askvortsov1 askvortsov1 force-pushed the sm/2637-list-discussions-eagerloading branch from b5c63ab to f32b471 Compare March 3, 2021 14:16
@SychO9 SychO9 mentioned this pull request Mar 4, 2021
13 tasks
Copy link
Member

@clarkwinkelmann clarkwinkelmann left a 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)) {
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)

@SychO9 SychO9 force-pushed the sm/2637-list-discussions-eagerloading branch from 22f6354 to 885f454 Compare March 7, 2021 20:28
Copy link
Member

@clarkwinkelmann clarkwinkelmann left a 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

@askvortsov1 askvortsov1 merged commit bc607e0 into master Mar 7, 2021
@askvortsov1 askvortsov1 deleted the sm/2637-list-discussions-eagerloading branch March 7, 2021 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet