Skip to content

Commit a48aad2

Browse files
authored
Merge pull request #42 from dachcom-digital/bugfix/memory-issue
fix memory issue when dealing with large lists (assets, documents, objects)
2 parents f2577c3 + f7ed3a1 commit a48aad2

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

UPGRADE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Upgrade Notes
22

3+
## 3.0.3
4+
- [IMPROVEMENT] fix memory issue when dealing with large lists (assets, documents, objects) (#41)
35
## 3.0.2
46
- [LICENSE] Dual-License with GPL and Dachcom Commercial License (DCL) added
57
## 3.0.1

src/Service/Builder/AssetListBuilder.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ public function buildByList(array $options): \Generator
3232
{
3333
$list = $this->getList($options);
3434

35-
foreach ($list->loadIdList() as $id) {
36-
if ($asset = Asset::getById($id)) {
35+
$idList = $list->loadIdList();
36+
$length = count($idList);
37+
for ($i = 0; $i < $length; $i++) {
38+
if ($asset = Asset::getById($idList[$i])) {
3739
yield $asset;
3840
}
41+
if ($i % 400 === 0) {
42+
\Pimcore::collectGarbage();
43+
}
3944
}
4045
}
4146

src/Service/Builder/DocumentListBuilder.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ public function buildByList(array $options): \Generator
3232
{
3333
$list = $this->getList($options);
3434

35-
foreach ($list->loadIdList() as $id) {
36-
if ($doc = Document::getById($id)) {
35+
$idList = $list->loadIdList();
36+
$length = count($idList);
37+
for ($i = 0; $i < $length; $i++) {
38+
if ($doc = Document::getById($idList[$i])) {
3739
yield $doc;
3840
}
41+
if ($i % 400 === 0) {
42+
\Pimcore::collectGarbage();
43+
}
3944
}
4045
}
4146

src/Service/Builder/ObjectListBuilder.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ public function buildByList(array $options): \Generator
3232
{
3333
$list = $this->getList($options);
3434

35-
foreach ($list->loadIdList() as $id) {
36-
if ($object = DataObject::getById($id)) {
35+
$idList = $list->loadIdList();
36+
$length = count($idList);
37+
for ($i = 0; $i < $length; $i++) {
38+
if ($object = DataObject::getById($idList[$i])) {
3739
yield $object;
3840
}
41+
if ($i % 400 === 0) {
42+
\Pimcore::collectGarbage();
43+
}
3944
}
4045
}
4146

0 commit comments

Comments
 (0)