Closed AugustMiller closed 3 years ago
Ideally all custom fields should not be immediately running any queries from normalizeValue()
. None of the built-in relational fields or Matrix do, for example – their normalizeValue()
methods return element query objects, but the queries won’t actually be executed unless something in the template tells it to.
The only way we could solve this is by moving all custom fields out of the default toArray()
results, so they’d only be included when explicitly requested by $extraFields
. Maybe that would be better, but it would be a breaking change so not something we could do until 4.0.
This sounds like a totally fine recommendation/principle—we'll raise with the map plugin authors, and brainstorm some PRs.
Thank you! 💞
Description
While doing some performance work, I noticed there were some out-of-place queries related to a SimpleMap field (ultimately reproduced with SmartMap, too) that uses data from another table.
This led to a realization that within the
group(…)
filter, each element was having its fields normalized (or, passed throughnormalizeValue
/normalizeFieldValue
, despite not being used.Ultimately, I don't really consider this a bug, so much as a strange side-effect of the
->toArray()
method that Elements inherit… is there a backwards-compatible alternative to this behavior (casting the attributes into the string templates)?Steps to reproduce
{% set entries = craft.entries({ section: 'mySection' }).all() | group('id') %}
This should be reproducible for any kind of field that does an additional query for external data in its
normalizeValue
method.Additional info