Skip to content

Define descendant relationship on Entry model #455

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

Draft
wants to merge 4 commits into
base: 4.x
Choose a base branch
from

Conversation

BobWez98
Copy link

I have changed the way the directdescendants are queried as the default Statamic way causes an N + 1 issue for us. This reduces a lot of queries.

The only problem still with this PR is the tests are failing. For some reason when creating entries in the tests it does not propagate them as they should. Does anyone have any idea? Or some pointers?

@ryanmitchell
Copy link
Contributor

Thanks for the PR. Can you provide some background information on how this improves performance for you, it would be great to understand where the need for this change is coming from.

@ryanmitchell ryanmitchell changed the title Descendant relationship Define descendant relationship on Entry model Jun 12, 2025
@BobWez98
Copy link
Author

We're currently developing a multisite with 12 languages. When in the control panel on an overview page with a lot of entries (50 per page) all the descendants are queried too, even though only having selected a specific site. This querying of the descendants cause a lot of unnecessary queries and make the control panel very slow:
Scherm­afbeelding 2025-06-12 om 09 16 09

With the relationship this reduces the number of queries executed:
Scherm­afbeelding 2025-06-12 om 09 16 56

@ryanmitchell
Copy link
Contributor

Thanks for clarifying, though looking at your debug bar the change has made both the memory usage and response time higher. Less queries but a slower response?

I've updated your PR to resolve the descendants being cached on the model itself.

@ryanmitchell
Copy link
Contributor

As this is no longer finding entries through the repository/facade we lose the blink cache on the entries returned, which is why there are so many more models being returned. A lot of these will be duplicates, so this PR has replaced one inefficiency with another. I understand the desire to get the query count down, but getting the model count minimised is of equal importance.

As it stands, I don't think this solution is the correct general approach - it may work in your use case but it would have a detrimental effect in others. The good thing is that you can already apply this to your install by specifying your own Entry class and Model in the config.

@ryanmitchell ryanmitchell marked this pull request as draft June 19, 2025 07: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.

2 participants