From 9dcbbdaf697cd7acaa207d4416c063808a18e925 Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Thu, 1 Feb 2024 15:55:17 +0100 Subject: [PATCH] Add alternative to memory limit --- src/Console/CsvImportCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/CsvImportCommand.php b/src/Console/CsvImportCommand.php index 8236089..3ce8a95 100644 --- a/src/Console/CsvImportCommand.php +++ b/src/Console/CsvImportCommand.php @@ -163,8 +163,8 @@ class CsvImportCommand extends Console $progressIndicator->advance(); $progressIndicator->setMessage('Importing... ' . (string) $count . ' records done.'); - // Flush to database if memory usage reaches limit. - if ((memory_get_usage() / $phpMemoryLimit) > $memoryLimit) { + // Flush to database if memory usage reaches limit or every 50.000 records. + if ((memory_get_usage() / $phpMemoryLimit) > $memoryLimit || ($count % 50000) === 0) { Database::getInstance()->flush([Record::class]); } }