verbb / hyper

A Craft CMS plugin for managing links, focusing on user experience.
Other
24 stars 15 forks source link

Eager loading not working at all #103

Open mihob opened 11 months ago

mihob commented 11 months ago

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

  1. Create an entry type with a hyper field
  2. 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

engram-design commented 11 months ago

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

mihob commented 11 months ago

Hmm okay, I gotta say, the performance impact compared to TypedLinkField is not exactly small.

Page with TypedLinkField:

SCR-20231124-bagw

Same page after migration to Hyper:

SCR-20231124-bbjx

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.

engram-design commented 11 months ago

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.

mihob commented 11 months ago

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

engram-design commented 11 months ago

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.

Screenshot 2023-11-24 at 8 29 12 pm

Screenshot 2023-11-24 at 8 27 24 pm

Maybe you can supply:

mihob commented 11 months ago

Sorry for my late reply.