diff --git a/UPGRADE.md b/UPGRADE.md index e7acfbb..921825d 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,7 @@ # Upgrade Notes +## 3.0.3 +- [IMPROVEMENT] fix memory issue when dealing with large lists (assets, documents, objects) (#41) ## 3.0.2 - [LICENSE] Dual-License with GPL and Dachcom Commercial License (DCL) added ## 3.0.1 diff --git a/src/Service/Builder/AssetListBuilder.php b/src/Service/Builder/AssetListBuilder.php index b32f246..d7a5325 100644 --- a/src/Service/Builder/AssetListBuilder.php +++ b/src/Service/Builder/AssetListBuilder.php @@ -32,10 +32,15 @@ public function buildByList(array $options): \Generator { $list = $this->getList($options); - foreach ($list->loadIdList() as $id) { - if ($asset = Asset::getById($id)) { + $idList = $list->loadIdList(); + $length = count($idList); + for ($i = 0; $i < $length; $i++) { + if ($asset = Asset::getById($idList[$i])) { yield $asset; } + if ($i % 400 === 0) { + \Pimcore::collectGarbage(); + } } } diff --git a/src/Service/Builder/DocumentListBuilder.php b/src/Service/Builder/DocumentListBuilder.php index f8e3ab9..69fae90 100644 --- a/src/Service/Builder/DocumentListBuilder.php +++ b/src/Service/Builder/DocumentListBuilder.php @@ -32,10 +32,15 @@ public function buildByList(array $options): \Generator { $list = $this->getList($options); - foreach ($list->loadIdList() as $id) { - if ($doc = Document::getById($id)) { + $idList = $list->loadIdList(); + $length = count($idList); + for ($i = 0; $i < $length; $i++) { + if ($doc = Document::getById($idList[$i])) { yield $doc; } + if ($i % 400 === 0) { + \Pimcore::collectGarbage(); + } } } diff --git a/src/Service/Builder/ObjectListBuilder.php b/src/Service/Builder/ObjectListBuilder.php index 2a62d54..31e42be 100644 --- a/src/Service/Builder/ObjectListBuilder.php +++ b/src/Service/Builder/ObjectListBuilder.php @@ -32,10 +32,15 @@ public function buildByList(array $options): \Generator { $list = $this->getList($options); - foreach ($list->loadIdList() as $id) { - if ($object = DataObject::getById($id)) { + $idList = $list->loadIdList(); + $length = count($idList); + for ($i = 0; $i < $length; $i++) { + if ($object = DataObject::getById($idList[$i])) { yield $object; } + if ($i % 400 === 0) { + \Pimcore::collectGarbage(); + } } }