FIX Don't try to call count() on an iterator

This commit is contained in:
Guy Sartorelli 2022-08-11 15:04:33 +12:00
parent 81beddc161
commit bf331072df
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A

View File

@ -1357,14 +1357,15 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li
$currentChunk = 0; $currentChunk = 0;
// Keep looping until we run out of chunks // 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 // Loop over all the item in our chunk
$count = 0;
foreach ($chunk as $item) { foreach ($chunk as $item) {
$count++;
yield $item; yield $item;
} }
if ($count < $chunkSize) {
if ($chunk->count() < $chunkSize) {
// If our last chunk had less item than our chunkSize, we've reach the end. // If our last chunk had less item than our chunkSize, we've reach the end.
break; break;
} }