Skip to content
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

Eager loading not working at all #103

Open
mihob opened this issue Nov 23, 2023 · 6 comments
Open

Eager loading not working at all #103

mihob opened this issue Nov 23, 2023 · 6 comments

Comments

@mihob
Copy link

mihob commented Nov 23, 2023

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
Copy link
Member

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
Copy link
Author

mihob commented Nov 23, 2023

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
Copy link
Member

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
Copy link
Author

mihob commented Nov 23, 2023

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
Copy link
Member

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:

  • Are you using any custom fields on your link types?
  • What does your template look like for outputting Hyper fields?

@mihob
Copy link
Author

mihob commented Nov 29, 2023

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.

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

No branches or pull requests

2 participants