Hi.
Ich lese mit dem nachfolgenden Code die Produkte einer Kategorie aus:
$criteria = new Criteria([ID]);
$criteria->addAssociation('nestedProducts');
/** @var CategoryEntity $category */
$category = $this->categoryRepository->search($criteria, $resolverContext->getSalesChannelContext()->getContext())->first();
Dies führ bei einem Kundenprojekt (der Zielkategorie sind 450 Produkte zugewiesen) zu folgenden Problem mit Fehler 500:
[2021-01-05 13:55:29] php.CRITICAL: Fatal Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\OutOfMemoryError(code: 0): Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) at /var/www/clients/client1/web2/web/vendor/shopware/core/Framework/Struct/CloneTrait.php:9)"} []
[2021-01-05 13:55:29] request.CRITICAL: Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\OutOfMemoryError: "Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes)" at /var/www/clients/client1/web2/web/vendor/shopware/core/Framework/Struct/CloneTrait.php line 9 {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\OutOfMemoryError(code: 0): Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) at /var/www/clients/client1/web2/web/vendor/shopware/core/Framework/Struct/CloneTrait.php:9)"} []
[2021-01-05 13:58:24] request.CRITICAL: Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\OutOfMemoryError: "Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 2097160 bytes)" at /var/www/clients/client1/web2/web/vendor/doctrine/dbal/lib/Doctrine/DBAL/SQLParserUtils.php line 223 {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\OutOfMemoryError(code: 0): Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 2097160 bytes) at /var/www/clients/client1/web2/web/vendor/doctrine/dbal/lib/Doctrine/DBAL/SQLParserUtils.php:223)"} []
[2021-01-05 14:03:08] php.CRITICAL: Fatal Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 27267072 bytes) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\OutOfMemoryError(code: 0): Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 27267072 bytes) at /var/www/clients/client1/web2/web/vendor/symfony/cache/Marshaller/DefaultMarshaller.php:47)"} []
Es wird hier ja lediglich eine Entity Suche durchgeführt… Verstehe nicht warum das zu einer solchen Last führt?! Jemand eine Idee? Hier die Funktion im Ganzen zum alle Eigenschafter einer Kategorie anhand der zugewiesenen Produkte zu ermitteln:
/**
* get all available properties of the given category
*
* @param $categoryConfig
* @param ResolverContext $resolverContext
* @return array
*/
private function getCategoryProperties($categoryConfig, ResolverContext $resolverContext)
{
$criteria = new Criteria([$categoryConfig->getValue()]);
$criteria->addAssociation('nestedProducts');
/** @var CategoryEntity $category */
$category = $this->categoryRepository->search($criteria, $resolverContext->getSalesChannelContext()->getContext())->first(); // hier kommt es zum Absturz!!!
$categoryPropertyIds = [];
foreach ($category->getNestedProducts()->getElements() as $product)
{
if (is_array($product->getPropertyIds())) {
$categoryPropertyIds = array_merge($categoryPropertyIds, $product->getPropertyIds());
}
}
return array_values(array_unique($categoryPropertyIds, SORT_REGULAR));
}
Gruß Mike