-
Notifications
You must be signed in to change notification settings - Fork 642
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
Live Preview has issues when Eager Loading with {% do %} #5065
Comments
Since you already have the entry, there is no performance benefit to eager-loading anything there except And ever since Craft 3.2, you shouldn’t have to jump through any hoops like #1787 for Live Preview. So all of your code there can be safely deleted, and whenever you are going to loop through {% set sponsorships = entry.sponsorships
.with(['sponsorLogo'])
.all() %}
{% for sponsorship in sponsorships %}
{% set sponsorLogo = sponsorship.sponsorLogo|first %}
{% if sponsorLogo %}
<img src="{{ sponsorLogo.url }}" alt="{{ sponsorLogo.title }}">
{% endif %}
{% endfor %} (Note that if |
Thanks Brandon, I removed all of the eager loading as you suggested and noticed an increase in DB queries and response time for the queries. It was about 10 extra queries and 30 ms on average. So performance looks to be better while eager loading all the fields. This does resolve the live preview issue. All the fields, in my example above, that are being eager loaded are relational fields. Asset fields, entries fields, and matrix fields. I believe I want to eager load all those types of elements as long as it results in a performance benefit. Is this a particular problem with me eager loading with Sorry for my confusion on this and thanks for your help! |
Sorry, it was a bit early when I replied and I overlooked what the middle chunk of your template is doing. The
So here’s the normal way you’d eager-load those fields:
|
While it’s still true that you shouldn’t eager-load Matrix blocks themselves when you already have the entry, it does turn out that there was a bug that prevented it from working. That has been fixed for the next release. |
Thanks a bunch for looking into this further, appreciate it! |
Description
I'm using
{% do %}
to eager load my entry information. I've had to create a work around for eager load matrix fields. I looked over issue #1787 but could only get my matrix blocks to display in live preview with the below work around. I'm also running into an issue with an entries field not display in live preview. Here is an implementation:Steps to reproduce
{% do craft.app.elements.eagerLoadElements() %}
Additional info
Admin Bar: 3.1.8.1
Blitz: 2.3.0
Calendar: 2.0.24
Calendar Links: 1.0.1
Content Stats: 2.1.1
CP Field Inspect: 1.0.6
Dumper: 2.0.0
Element API: 2.6.0
Freeform: 3.3.2
Grid: 1.2.2
Guide: 1.4.0
Imager: v2.1.10
Image Resizer: 2.0.6
Minify: 1.2.9
Navigation: 1.1.13
Preparse Field: v1.1.0
Redactor: 2.4.0
SEO: 3.2.27
Store Hours: 2.1.1.1
Typed link field: 1.0.19
Typogrify: 1.1.18
The text was updated successfully, but these errors were encountered: