Skip to content

Commit 09aa5b6

Browse files
committed
fix memory issue when dealing with large asset and document lists
1 parent 86ffead commit 09aa5b6

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

UPGRADE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Upgrade Notes
22

33
## 3.0.3
4-
- [IMPROVEMENT] fix memory issue when dealing with large object lists (#41)
4+
- [IMPROVEMENT] fix memory issue when dealing with large lists (assets, documents, objects) (#41)
55
## 3.0.2
66
- [LICENSE] Dual-License with GPL and Dachcom Commercial License (DCL) added
77
## 3.0.1

src/Service/Builder/AssetListBuilder.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ 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+
for ($i = 0; $i < count($idList); $i++) {
37+
if ($asset = Asset::getById($idList[$i])) {
3738
yield $asset;
3839
}
40+
if ($i % 400 === 0) {
41+
\Pimcore::collectGarbage();
42+
}
3943
}
4044
}
4145

src/Service/Builder/DocumentListBuilder.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ 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+
for ($i = 0; $i < count($idList); $i++) {
37+
if ($doc = Document::getById($idList[$i])) {
3738
yield $doc;
3839
}
40+
if ($i % 400 === 0) {
41+
\Pimcore::collectGarbage();
42+
}
3943
}
4044
}
4145

0 commit comments

Comments
 (0)