Мне нужно импортировать файл CSV, содержащий около 20 000 строк. Этот CSV считывается с FTP-сервера, который будет обновляться каждые 30 минут. Но код, который я написал, уже импортируется более 45 минут. Это очень медленно. Может ли кто-нибудь помочь мне.
foreach ($readers as $key => $row) {
$totalRecords +=1;
$filterArray = $this->entityManager->getRepository(Article::class)->findBy(['id' => $row['id']]);
if (empty($filterArray)) {
$notFoundRecords +=1;
continue;
}
$foundRecords +=1;
$this->processPriceRow($row);
}
protected function processPriceRow($row)
{
$existingRecord = $this->entityManager
->getRepository(WareHouse::class)
->findBy(['id' => $row['product_id']]);
if (empty($existingRecord)) {
return $this->fillArticleWareHouse($row);
}
}
protected function fillArticleWareHouse($row, $i, $batchSize)
{
$newWareHouse = new WareHouse();
....
....
...
// Insert.
$this->entityManager->persist($newWareHouse);
$this->entityManager->flush();
}
Я думаю о сохранении данных каждый на основе batchSize = 100. Но поскольку у меня есть функция внутри функции, я также не могу это реализовать.
flush
после сохранения каждой сущности? Это очень поможет - person Nico Haase   schedule 20.07.2020