Loading models eagerly
Closed this issue · 2 comments
Now that @fritzmg has debugged the memory issues caused by eagerly loaded models, I want to discuss eager loading in general. Take this code for example:
calendar-bundle/src/Resources/contao/classes/Events.php
Lines 427 to 434 in 7bd32ae
With array('eager'=>true)
we instruct Contao to also load all related models. Here's what we get:
ArticleModel
PageModel
(pid
)UserModel
(author
)
However, we are not using the UserModel
in this case, so we would not have needed to create it. On the other hand, using array('eager'=>true)
has saved us one additional database query.
@contao/developers Would you prefer having more database queries and no unneeded models over having less database queries and potentially unneeded models?
As discussed in Mumble on July 5th, we should generally disable eager loading in DCAs ('load'=>'eager'
) and never load collections eagerly. In other cases like above, it might be helpful.
Changed where applicable (see commits above).