-
Notifications
You must be signed in to change notification settings - Fork 115
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
Repeated database queries from BaseElement::getAreaRelationName() #928
Comments
Just a quick thought — wasn't there an enhancement from @mfendeksilverstripe around gettoppage or similar? Not sure if it applies here but it's the first thing that came to mind. |
You're right @michalkleiner , we do have a feature addressing this. It's opt in in |
Unless I’m misunderstanding something, I’m not sure that’d help in this case. The code in question has already fetched the page, it’s another query after that that then fetches an |
You're right @kinglozzer, the Top page feature is focused on page lookup from blocks. I think it's reasonable to add a cached call for elemental area as well. |
FIX: Save repeated database queries to fetch elemental area name (fixes #928)
Pull request merged. It'll be automatically tagged by GitHub Actions. |
During element rendering,
forTemplate()
callsgetRenderTemplates()
, which in turn callsgetAreaRelationName()
to help build a list of applicable templates (presumably so that elements can be rendered differently based on which area they belong to).BaseElement::getAreaRelationName()
calls$this->Parent()
, which runs through a typical flow for fetching a has_one component. However, these calls aren’t cached so this results in an additional database query for each element as it’s rendered:silverstripe-elemental/src/Models/BaseElement.php
Lines 758 to 760 in f626840
I’d suggest we replace this with something like:
PR
The text was updated successfully, but these errors were encountered: