victoire icon indicating copy to clipboard operation
victoire copied to clipboard

[Insight] The EntityManager should not be flushed within a loop - in Bundle/…/BusinessEntitySubscriber.php, line 155

Open lenybernard opened this issue 7 years ago • 0 comments

in Bundle/BusinessEntityBundle/EventSubscriber/BusinessEntitySubscriber.php, line 155

Calling flush is a resource intensive operation, especially when a lot of entities are managed by Doctrine. You should pass the entity you want to flush as parameter, or avoid flushing inside a loop.

                        $newSlug = $entity->getSlug();
                        $businessPage->setName($virtualBusinessPage->getName());
                        $businessPage->setSlug($virtualBusinessPage->getSlug());

                        $entityManager->persist($businessPage);
                        $entityManager->flush();
                    }
                }
            }
        }
    }

Posted from SensioLabsInsight

lenybernard avatar Jun 01 '17 18:06 lenybernard