From cd0fa220e3f8c06dea930d1d2bbdf2bca3d2e310 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 11 Feb 2025 16:33:29 +0000 Subject: [PATCH 1/2] Improve performance of the data reference updaters --- .../Concerns/GetsItemsContainingData.php | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Listeners/Concerns/GetsItemsContainingData.php b/src/Listeners/Concerns/GetsItemsContainingData.php index 2a9c8a68a70..2c4842aa53c 100644 --- a/src/Listeners/Concerns/GetsItemsContainingData.php +++ b/src/Listeners/Concerns/GetsItemsContainingData.php @@ -2,6 +2,7 @@ namespace Statamic\Listeners\Concerns; +use Illuminate\Support\LazyCollection; use Statamic\Facades\Entry; use Statamic\Facades\GlobalSet; use Statamic\Facades\Term; @@ -16,10 +17,25 @@ trait GetsItemsContainingData */ public function getItemsContainingData() { - return collect() - ->merge(Entry::all()) - ->merge(Term::all()) - ->merge(GlobalSet::all()->flatMap(fn ($set) => $set->localizations()->values())) - ->merge(User::all()); + $collections = [ + LazyCollection::make(function () { + yield from Entry::query()->lazy(); + }), + LazyCollection::make(function () { + yield from Term::query()->lazy(); + }), + LazyCollection::make(function () { + yield from GlobalSet::all()->flatMap(fn ($set) => $set->localizations()->values()); + }), + LazyCollection::make(function () { + yield from User::query()->lazy(); + }), + ]; + + return LazyCollection::make(function () use ($collections) { + foreach ($collections as $collection) { + yield from $collection; + } + }); } } From 09968bbccbb9bfe0a36904de2eba0e859bd1b75a Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 11 Feb 2025 16:39:37 +0000 Subject: [PATCH 2/2] Update return type in docblock --- src/Listeners/Concerns/GetsItemsContainingData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Listeners/Concerns/GetsItemsContainingData.php b/src/Listeners/Concerns/GetsItemsContainingData.php index 2c4842aa53c..161b043ebce 100644 --- a/src/Listeners/Concerns/GetsItemsContainingData.php +++ b/src/Listeners/Concerns/GetsItemsContainingData.php @@ -13,7 +13,7 @@ trait GetsItemsContainingData /** * Get items containing data. * - * @return \Illuminate\Support\Collection + * @return \Illuminate\Support\LazyCollection */ public function getItemsContainingData() {