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

perf: Allow loading relations in other discussion endpoints #3191

Merged
merged 1 commit into from
Dec 13, 2021

Conversation

SychO9
Copy link
Member

@SychO9 SychO9 commented Dec 9, 2021

Related to #3116

Changes proposed in this pull request:
Missed the other two endpoints which also attempt to load the tags.state relationship. The impact is the same.

Reviewers should focus on:
I really dislike the implementation in ShowDiscussionsController, it's becoming very bloated, and that's mostly due to how the posts of the discussion are loaded. I feel like it would be better to load those posts by directly getting the result from the posts endpoint, we should look into refactoring it in another major version.

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

@@ -98,9 +99,9 @@ protected function data(ServerRequestInterface $request, Document $document)
$this->includePosts($discussion, $request, $postRelationships);
}

$discussion->load(array_filter($include, function ($relationship) {
$this->loadRelations(new Collection([$discussion]), array_filter($include, function ($relationship) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that I like creating the collection here, it might be better to modify loadRelations to accept either a single model or a collection of models, as they both have the same methods, though I dislike that as well, I wish there was a common interface for this, there is a trait, but I don't think you can use traits for typing.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it like this for now; it's not perfect, but it's good enough.

re: typing, we can figure out the PHPStan implementation later.

Copy link
Sponsor Member

@askvortsov1 askvortsov1 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 not gonna lie, the complexity of this eager loading system has reached such a level that it is very difficult for me to fully understand what we're doing and why. I'm approving because we need to fix the performance issue, but I think this is a clear signal that we are limited by our current json-api-php usage, and yet another reason to completely redo the JSON:API layers of our stack for v2.

@@ -98,9 +99,9 @@ protected function data(ServerRequestInterface $request, Document $document)
$this->includePosts($discussion, $request, $postRelationships);
}

$discussion->load(array_filter($include, function ($relationship) {
$this->loadRelations(new Collection([$discussion]), array_filter($include, function ($relationship) {
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it like this for now; it's not perfect, but it's good enough.

re: typing, we can figure out the PHPStan implementation later.

@SychO9 SychO9 merged commit c7791b6 into master Dec 13, 2021
@SychO9 SychO9 deleted the sm/tag-state-additional-perf-fix branch December 13, 2021 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants