I have a problem with the import data process. First: I have used the factory creator to create a Model set data and save but the problem when I have 400k Item to save.
--- Constructor
\Magento\Sales\Model\OrderFactory $orderFactory
$this->orderFactory = $orderFactory;
--- Process Function (100 item of row) //Another function have 400k row.
public function process($data){
foreach($data as $row){
$order = $this->orderFactory->create();
$order->setData($row);
$order->save();
}
}
--- Memory usage;
Memory Usage: 8=1.89402008057 (0)
Memory Usage: 3846.87700 (200k Item)
I'm trying to improve that process using create 1 Object of the Model.
--- Constructor
\Magento\Sales\Model\OrderFactory $orderFactory
$this->order = $orderFactory->create();
--- Process Function
public function process($data){
foreach($data as $row){
$order = $this->order->clearInstance();
$order->unsetData(null);
$order->setData($row);
$order->save();
}
}
Memory usage was reduce.
Memory Usage: 881.244 (0)
Memory Usage: 2146.8836288 (300k).
---- About 100 items was used 1.1M of the memory
Memory Usage: 2125.8544769287 (260k)
Memory Usage: 2126.9217758179 (260100)
Any tips for reducing memory usage to create Magento 2 Model. Instead of the insert to the database using Mysql query.
Thank for any tip.