Skip to content

Commit 22e90f3

Browse files
[5.x] Improve performance of the data reference updaters (#11442)
1 parent 2357356 commit 22e90f3

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/Listeners/Concerns/GetsItemsContainingData.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Statamic\Listeners\Concerns;
44

5+
use Illuminate\Support\LazyCollection;
56
use Statamic\Facades\Entry;
67
use Statamic\Facades\GlobalSet;
78
use Statamic\Facades\Term;
@@ -12,14 +13,29 @@ trait GetsItemsContainingData
1213
/**
1314
* Get items containing data.
1415
*
15-
* @return \Illuminate\Support\Collection
16+
* @return \Illuminate\Support\LazyCollection
1617
*/
1718
public function getItemsContainingData()
1819
{
19-
return collect()
20-
->merge(Entry::all())
21-
->merge(Term::all())
22-
->merge(GlobalSet::all()->flatMap(fn ($set) => $set->localizations()->values()))
23-
->merge(User::all());
20+
$collections = [
21+
LazyCollection::make(function () {
22+
yield from Entry::query()->lazy();
23+
}),
24+
LazyCollection::make(function () {
25+
yield from Term::query()->lazy();
26+
}),
27+
LazyCollection::make(function () {
28+
yield from GlobalSet::all()->flatMap(fn ($set) => $set->localizations()->values());
29+
}),
30+
LazyCollection::make(function () {
31+
yield from User::query()->lazy();
32+
}),
33+
];
34+
35+
return LazyCollection::make(function () use ($collections) {
36+
foreach ($collections as $collection) {
37+
yield from $collection;
38+
}
39+
});
2440
}
2541
}

0 commit comments

Comments
 (0)