hyper
hyper copied to clipboard
Eager loading not working at all
Describe the bug
It looks like eager loading for hyper fields won't work at all.
The following query as an example, link is the hyper field
{% set navigation = craft.entries().section('navigation').with('link').all() %}
{% for entry in navigation %}
<a href="{{entry.link.url}}">{{entry.link.text}}</a>
{% endfor %}
Results in the following error:
Method craft\elements\ElementCollection::url does not exist.
Steps to reproduce
- Create an entry type with a hyper field
- Create a query with eager loading of the hyper field
Craft CMS version
Craft Pro 4.5.11
Plugin version
1.1.16
Multi-site?
Yes
Additional context
No response
Hyper links can't be eager loaded, as they aren't elements. If we're talking about eager loading through a Hyper field to any custom fields on a link, that's not supported.
If the Hyper link refers to an element like an Entry, that's already heavily cached, and there shouldn't be any performance hits with n+1 queries. Hyper already knows the link information, so there's no performant impact to "fix" with eager loading
Hmm okay, I gotta say, the performance impact compared to TypedLinkField is not exactly small.
Page with TypedLinkField:
Same page after migration to Hyper:
The render time fluctuates somewhat, in the example they are now the same, but in several tests it is rather 30-40ms lower with TypedLinkField.
Above all, the significantly higher RAM requirement is a little concerning.
That's quite interesting to see, last I checked things were nowhere near that different! Just to confirm - are you testing with a single link, linked to an Entry?
There are by nature going to be more database queries, as Hyper fields use field layouts for custom fields, whereas any other link plugin doesn't do this, but that should be roughly the only difference.
There should be about 20 link fields in total. Distributed over the navigation and a "content builder" matrix field. All links are of type entry
So just doing some quick tests, running 10 link fields on a page, all multiple links (5 each) relating to entries, the before and after adding Hyper templating references.
Maybe you can supply:
- Are you using any custom fields on your link types?
- What does your template look like for outputting Hyper fields?
Sorry for my late reply.
- No, I do not use custom fields.
- It varies but the different links are usually twig includes that receive url, type, target and text and then render the link.