From 5bdfaea78a41a5ce05c67942cbe2340a9e37a400 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 11 Aug 2022 15:04:33 +1200 Subject: [PATCH] FIX Don't try to call count() on an iterator --- src/ORM/DataList.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ORM/DataList.php b/src/ORM/DataList.php index 124ceefb0..817efbdb8 100644 --- a/src/ORM/DataList.php +++ b/src/ORM/DataList.php @@ -1349,14 +1349,15 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li $currentChunk = 0; // Keep looping until we run out of chunks - while ($chunk = $this->limit($chunkSize, $chunkSize * $currentChunk)->getIterator()) { + while ($chunk = $this->limit($chunkSize, $chunkSize * $currentChunk)) { // Loop over all the item in our chunk + $count = 0; foreach ($chunk as $item) { + $count++; yield $item; } - - if ($chunk->count() < $chunkSize) { + if ($count < $chunkSize) { // If our last chunk had less item than our chunkSize, we've reach the end. break; }