From 26d59944e014cd0321e23ec6f7622e0689f5a1fa Mon Sep 17 00:00:00 2001 From: Mojmir Fendek Date: Tue, 10 May 2022 15:43:51 +1200 Subject: [PATCH 1/2] ENH: RemoveAll() memory performance enhancement. --- src/ORM/DataList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ORM/DataList.php b/src/ORM/DataList.php index fbd93412d79..72dfaf02ef2 100644 --- a/src/ORM/DataList.php +++ b/src/ORM/DataList.php @@ -1174,7 +1174,7 @@ public function shuffle() */ public function removeAll() { - foreach ($this as $item) { + foreach ($this->getGenerator() as $item) { $this->remove($item); } return $this; From b864c11b12abfc943aecd0a5e6f05db34ed4697f Mon Sep 17 00:00:00 2001 From: Mojmir Fendek Date: Fri, 13 May 2022 12:11:18 +1200 Subject: [PATCH 2/2] PR fixes. --- tests/php/ORM/DataListTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/php/ORM/DataListTest.php b/tests/php/ORM/DataListTest.php index 481b4a316cd..dc80aaf40a0 100755 --- a/tests/php/ORM/DataListTest.php +++ b/tests/php/ORM/DataListTest.php @@ -458,6 +458,17 @@ public function testRemoveByID() $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() */