-
-
Notifications
You must be signed in to change notification settings - Fork 61
Description
I am processing a collection of records in a loop and for each record in this collection I call a generator method in which I process a different collection in this record. I know that there may be a lot of records and these records can also have a lot of records, so I want to process them sequentially, but the ORM optimizes the queries and pulls out data that I don't need yet, which slows down the queries and increases memory requirements. This goes against the point of why I am using the generator.
This is the sample code:
function generate(Author $author): \Generator
{
// this could be very slow
$books = $author->books->toCollection()->findBy(/* ... */)->orderBy(/* ... */);
foreach ($books as $book) {
// ....
yield $something;
}
}
$authors = $orm->authors->findAll();
foreach ($authors as $author) {
foreach (generate($author) as $something) {
// ...
}
}I was looking for a way to turn off this optimization and it seemed to me that it would be enough to add this line to the beginning of the method generate():
$author->setPreloadContainer(null);But I don't know if it has any other consequences.
How about making some of this?
- create a new and appropriately named entity method to disable this optimization
- add information to the documentation