oasmobile / php-dynamodb-odm

ODM for dynamodb
MIT License
13 stars 18 forks source link

How iterate and save huge data file #13

Closed tfe2012 closed 6 years ago

tfe2012 commented 7 years ago

$refreshCount = 0;

while (($data = fgetcsv($handle, 1000, ",")) !== false) { $refreshCount++; $supplierProduct = new SupplierProduct(); $this->supplierProductModel->save($supplierProduct); if ($refreshCount > 100) { // Point 1. $this->supplierProductModel->clear(); $refreshCount = 0; } }

// Point 2. $this->supplierModel->save($supplier);

If I try read file, and not cleaning (point 1) itemManager, I get memory leak, ItemManager use all ram.

If I cleaning, than on point 2 save doesn't work.

Save looks like: $version++; $object->setVersion($version); $this->itemManager->flush();

A question is how to iterate huge files?

no7mks commented 7 years ago

on item-manager clear(), all persisted data is cleared. And your $supplier object is not managed anymore by item-manager.

One word around: you can clear only items as SupplierProduct by:

$itemManager->getRepository(SupplierProduct::class)->clear();
tfe2012 commented 7 years ago

Thx, now I understand idea. If you can, it would be great to add this information to information.