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 #341

Open
plumduffer opened this issue Feb 8, 2023 · 3 comments
Open

Eager Loading not working #341

plumduffer opened this issue Feb 8, 2023 · 3 comments

Comments

@plumduffer
Copy link

Describe the bug

I am trying to use eager loading to cut down on duplicate queries and I have noticed that eager loading doesn't seem to be doing anything with this plugin.

For example, here is one of my lines:

{% set primaryNavigation = craft.navigation.nodes('primaryNavigation').level(1).with(['children.children']).all() %}

While everything is functional, I noticed there is no difference in the amount of queries whether the with function is there or not. Additionally, when die and dumping like this {% dd primaryNavigation[0].children %}, it displays that the type is of verbb\navigation\elements\db\NodeQuery#1. Should this not be an array?

Is anyone else currently having this issue?

Steps to reproduce

  1. Try and eager load child nodes.
  2. Notice it doesn't work.

Craft CMS version

4.3.7.1

Plugin version

2.0.16

Multi-site?

Yes

Additional context

No response

@plumduffer
Copy link
Author

My workaround for the time being:

{% set primaryNavigation = craft.navigation.nodes('primaryNavigation').all() %}

{% for navItem in primaryNavigation|filter(x => x.level == 1) %}
    {% set childrenNav = primaryNavigation|filter(x => x.level > 1 and x.parent.id == navItem.id) %}
{% endfor %}

And so on.

@mightyfineyall
Copy link

mightyfineyall commented Feb 10, 2023

Having this issue as well. On a local dev site with only 3 nodes and one subnode:

Without eager loading (children called using .all()):

image

With eager loading as per docs:

image

Removing the Navigation query entirely, leaving everything else:

image

Interestingly enough, ripping everything out of the header file except for this one line:

{% set primaryNodes = craft.navigation.nodes('headerNavigation').level(1).with(['children']).all() %}

Still leaves us at 100ms:

image

That's odd.

@plumduffer updated my local to 4.3.8.2 and it seems to be fixed, likely related to craftcms/cms#12648:

image

@engram-design
Copy link
Member

There have been some rough issues with eager loading in Craft itself, so be sure to get updated before proceeding further.

However, the lack of eager-loading nodes is a well-known issue. While the nodes themselves can be eager-loaded, the linked-to elements cannot and is at the moment a Craft limitation.

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

3 participants