You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{% for entry in craft.entries.section('news').all() %}
{% if list.getItem(entry) %}
<a href="{{ list.removeItemUrl(entry) }}">Remove from List</a>
{% else %}
<a href="{{ list.addItemUrl(entry) }}">Add to List</a>
{% endif %}
{% endfor %}
However list.getItem(entry) appears to cause a per-element DB query, resulting in many extra queries on long listing pages. I was going to look into solving this with some simple Twig arrays loaded upfront, but before I do that I wanted to check I wasn't missing something or making a mistake/omission in my implementation. Can we eager load this information in getUserList() or something?
Additional context
No response
The text was updated successfully, but these errors were encountered:
So while we do eager-load things with list->getItems(), this function doesn't use that, purely because you can pass in additional query params as a second argument.
I'll give this some extra thought for when you supply additional params, as I might have to make that a breaking change to just filter the eager-loaded items (with your provided params) rather than element query params. But this is going to disrupt anyone doing non-equality checks in params.
But - for everyone else that just wants to check an element "normally", I think we certainly should be using the eager-loaded items, and filter just that.
Updated for the next release. To get this early, run composer require verbb/wishlist:"dev-craft-5 as 3.0.3".
Question
In your docs for checking if an item is in the list, you have this:
However
list.getItem(entry)
appears to cause a per-element DB query, resulting in many extra queries on long listing pages. I was going to look into solving this with some simple Twig arrays loaded upfront, but before I do that I wanted to check I wasn't missing something or making a mistake/omission in my implementation. Can we eager load this information ingetUserList()
or something?Additional context
No response
The text was updated successfully, but these errors were encountered: