Merge pull request #10307 from silverstripe-terraformers/feature/removal-all-enhancement

ENH: RemoveAll() memory performance enhancement.
This commit is contained in:
Guy Sartorelli 2022-05-13 14:00:29 +12:00 committed by GitHub
commit c0ff638cd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -1174,7 +1174,7 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li
*/
public function removeAll()
{
foreach ($this as $item) {
foreach ($this->getGenerator() as $item) {
$this->remove($item);
}
return $this;

View File

@ -458,6 +458,17 @@ class DataListTest extends SapphireTest
$this->assertNull($list->byID($id));
}
/**
* Test DataList->removeAll()
*/
public function testRemoveAll()
{
$list = Team::get();
$this->assertGreaterThan(0, $list->count());
$list->removeAll();
$this->assertCount(0, $list);
}
/**
* Test DataList->canSortBy()
*/