Iterate to many entitys
okuehne opened this issue · comments
What is the common way to iterate through many entities, for example a thousand products or more?
Now i do it in this way, but it feels not good, what is your solution?
private function getProducts(): \Generator
{
$criteria = new Criteria();
$productRepository = RepositoryFactory::create(ProductDefinition::ENTITY_NAME);
do {
$result = $productRepository->search($criteria, $this->getContext());
/** @var ProductEntity $product */
foreach ($result->getEntities() as $product) {
yield $product;
}
$criteria->setPage($criteria->getPage() + 1);
} while (($result->count()) === $criteria->getLimit());
}
if i remove the limit with $criteria->setLimit(null);
i got the Allowed memory size
error
Hi @OliverKuehne
Thanks for the feedback, I will take a deeper look into this and give my idea soon. Any other suggestion from anyone is welcome :)