If I loop pages fetched with find("template=$template, field=mytext"), calling $page->mytext makes a database query for each page that do not have mytext value. This causes an "N+1 queries problem", potentially making a lot of unneeded queries.
Expected behavior
field=mytext should cache both the value and absence of a value, and no further database queries is needed when $page->mytext is accessed.
Actual behavior
For each page without mytext, $page->mytext triggers the query
SELECT field_mytext.data AS `mytext__data` FROM `field_mytext` WHERE field_mytext.pages_id=1015`
Short description of the issue
If I loop pages fetched with
find("template=$template, field=mytext")
, calling$page->mytext
makes a database query for each page that do not havemytext
value. This causes an "N+1 queries problem", potentially making a lot of unneeded queries.Expected behavior
field=mytext
should cache both the value and absence of a value, and no further database queries is needed when$page->mytext
is accessed.Actual behavior
For each page without
mytext
,$page->mytext
triggers the queryOptional: Suggestion for a possible fix
I suspect this to be a regression of https://github.com/processwire/processwire/commit/4344df336b0e8839e71c809b37d0a73bd1d7c2f5.
I believe the code should read:
Steps to reproduce the issue
mytext
tobasic-page
mytext
for one pagemytext
.Setup/Environment