Symfony2 컨트롤러에서 $em->flush()
에 관한 질문이 있습니다. 내 테이블에 ~ 40,000 VEHICULES를 가지고 있기 때문에Symfony2 flush() 엔티티
$v = $em->getRepository("ApplicationAdminBundle:VehiculeCompute")->findAll();
foreach ($v as $vehicule) {
[...]
$somme = {"compute before"};
$veh = $em->getRepository("ApplicationAdminBundle:VehiculeCompute")->find($vehicule->getIdvehicules());
$veh->setTaxeadditionnelle($somme);
$em->flush();
$total++;
}
그래서,이 루프를 실행하기 위해, 내 스크립트는 시간이 오래 걸릴.
나는 각 루프에서 $em->flush()
는
$v = $em->getRepository("ApplicationAdminBundle:VehiculeCompute")->findAll();
$k = 0;
foreach ($v as $vehicule) {
[...]
$somme = {"compute before"};
$veh[$k] = $em->getRepository("ApplicationAdminBundle:VehiculeCompute")->find($vehicule->getIdvehicules());
$veh[$k]->setTaxeadditionnelle($somme);
$total++;
}
$em->flush(); // Flush all of vehicule update ?!
unset($veh);
이 버전은 작업 할 수 ... 필요하지 않습니다 가정? 감사합니다.
초기 생각은 ORM이 부적절한 경우입니다. Doctrine 쿼리 작성기를 사용하여 DBAL 계층에 직접 말할 수 있습니다. – lonesomeday
Doctrine 문서에서 일괄 처리에 대한 정보가 있습니다 - http://docs.doctrine-project.org/en/2.0.x/reference/batch-processing.html#bulk-inserts – qooplmao
@Prisoner'persist'는 지속성을위한 것입니다 새로운 엔티티는 이미 지속 된 엔티티를 업데이트 할 때 사용되어서는 안됩니다. –