22
33namespace Statamic \Entries ;
44
5+ use Statamic \Contracts \Entries \Collection as Contract ;
6+ use Statamic \Data \ExistsAsFile ;
57use Statamic \Facades ;
6- use Statamic \Support \Arr ;
7- use Statamic \Facades \File ;
8- use Statamic \Facades \Site ;
8+ use Statamic \Facades \Blink ;
9+ use Statamic \Facades \Blueprint ;
910use Statamic \Facades \Entry ;
11+ use Statamic \Facades \File ;
1012use Statamic \Facades \Search ;
13+ use Statamic \Facades \Site ;
1114use Statamic \Facades \Stache ;
12- use Statamic \Facades \Taxonomy ;
13- use Statamic \Facades \Blueprint ;
1415use Statamic \Facades \Structure ;
15- use Statamic \Data \ExistsAsFile ;
16+ use Statamic \Facades \Taxonomy ;
17+ use Statamic \Support \Arr ;
1618use Statamic \Support \Traits \FluentlyGetsAndSets ;
17- use Statamic \Contracts \Entries \Collection as Contract ;
1819
1920class Collection implements Contract
2021{
@@ -23,7 +24,6 @@ class Collection implements Contract
2324 protected $ handle ;
2425 protected $ route ;
2526 protected $ mount ;
26- protected $ mountedEntry ;
2727 protected $ title ;
2828 protected $ template ;
2929 protected $ layout ;
@@ -266,6 +266,9 @@ public function save()
266266 {
267267 Facades \Collection::save ($ this );
268268
269+ Blink::flush ('collection-handles ' );
270+ Blink::flushStartingWith ("collection- {$ this ->id ()}" );
271+
269272 optional ($ this ->structure ())->updateEntryUris ();
270273
271274 return $ this ;
@@ -499,7 +502,10 @@ public function structure($structure = null)
499502 return $ this
500503 ->fluentlyGetOrSet ('structure ' )
501504 ->getter (function ($ structure ) {
502- return is_string ($ structure ) ? Structure::findByHandle ($ structure ) : $ structure ;
505+ $ key = "collection- {$ this ->id ()}-structure- {$ structure }" ;
506+ return is_string ($ structure ) ? Blink::once ($ key , function () use ($ structure ) {
507+ return Structure::findByHandle ($ structure );
508+ }) : $ structure ;
503509 })
504510 ->args (func_get_args ());
505511 }
@@ -532,7 +538,9 @@ public function mount($page = null)
532538 return $ this
533539 ->fluentlyGetOrSet ('mount ' )
534540 ->getter (function ($ mount ) {
535- return $ this ->mountedEntry = $ this ->mountedEntry ?? Entry::find ($ mount );
541+ return Blink::once ("collection- {$ this ->id ()}-mount- {$ mount }" , function () use ($ mount ) {
542+ return Entry::find ($ mount );
543+ });
536544 })
537545 ->args (func_get_args ());
538546 }
@@ -542,9 +550,12 @@ public function taxonomies($taxonomies = null)
542550 return $ this
543551 ->fluentlyGetOrSet ('taxonomies ' )
544552 ->getter (function ($ taxonomies ) {
545- return collect ($ taxonomies )->map (function ($ taxonomy ) {
546- return Taxonomy::findByHandle ($ taxonomy );
547- })->filter ();
553+ $ key = "collection- {$ this ->id ()}-taxonomies- " .md5 (json_encode ($ taxonomies ));
554+ return Blink::once ($ key , function () use ($ taxonomies ) {
555+ return collect ($ taxonomies )->map (function ($ taxonomy ) {
556+ return Taxonomy::findByHandle ($ taxonomy );
557+ })->filter ();
558+ });
548559 })
549560 ->args (func_get_args ());
550561 }
0 commit comments