Symfony 更新条令中的实体需要太多时间
我有以下更新SalesOrder实体的代码Symfony 更新条令中的实体需要太多时间,symfony,doctrine,Symfony,Doctrine,我有以下更新SalesOrder实体的代码 public function updateAction($id) { $securityContext = $this->get('security.context'); $em = $this->getDoctrine()->getEntityManager(); $entity = $em->getRepository('CIInventoryBundle:SalesOrder')->find
public function updateAction($id)
{
$securityContext = $this->get('security.context');
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('CIInventoryBundle:SalesOrder')->find($id);
$editForm = $this->createForm(new SalesOrderType($securityContext), $entity);
$currentTotal = $entity->getTotal();
$currentStatus = $entity->getStatus();
try {
$entity->isEditable();
} catch (\Exception $e){
$this->get('session')->setFlash('alert-error', $e->getMessage());
return $this->redirect($this->generateUrl('salesorder_show', array('id' => $entity->getId())));
}
$originalItems = array();
foreach ($entity->getItems() as $item) {
$originalItems[] = $item;
}
$request = $this->getRequest();
$editForm->bindRequest($request);
if ($editForm->isValid()) {
try {
$entity->validateStatusChange($currentStatus, $currentTotal);
} catch (\Exception $e) {
$this->get('session')->setFlash('alert-error', $e->getMessage());
return $this->redirect($this->generateUrl('salesorder_show', array('id' => $id)));
}
foreach ($entity->getItems() as $item) {
//adjust the reserved in the inventory
$item->adjustReserved();
foreach ($originalItems as $key => $toDel) {
if ($toDel->getId() === $item->getId()) {
unset($originalItems[$key]);
}
}
}
foreach ($originalItems as $item) {
$em->remove($item);
}
$entity->setUpdatedAt(new \DateTime('now'));
$em->persist($entity);
$em->flush();
$this->get('session')->setFlash('alert-success', 'Record has been updated successfully!');
return $this->redirect($this->generateUrl('salesorder_show', array('id' => $id)));
} else {
$this->get('session')->setFlash('alert-error', 'Please fill in the correct values.');
$variantForm = $this->createForm(new AddVariantSalesOrderType());
}
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'variant_form' => $variantForm->createView(),
);
}
当我运行这段代码时,我得到了“超过了最大执行时间”。我已经将php.ini中的最大执行时间更改为2分钟
我可以优化我的代码吗
谢谢!这可能不需要花费2分钟的时间……我会开始分离一些零碎的东西,这样您就可以运行一个页面,然后使用Symfony分析器查看它的速度有多慢。另外,如果您真的认为最长执行时间应该只需要2分钟以上,请将其更改为无限。sql分析器显示任何慢查询?