@@ -22,6 +22,9 @@ abstract class Tree implements ContainsQueryableValues, Contract, Localization
2222 protected $ locale ;
2323 protected $ tree = [];
2424 protected $ cachedFlattenedPages ;
25+ protected $ cachedFlattenedPagesById ;
26+ protected $ cachedFlattenedPagesByReference ;
27+ protected $ cachedFlattenedPageOrder ;
2528 protected $ withEntries = false ;
2629 protected $ uriCacheEnabled = true ;
2730
@@ -143,17 +146,17 @@ public function uriCacheEnabled()
143146
144147 public function find ($ id ): ?Page
145148 {
146- return $ this ->flattenedPages ()
147- ->keyBy ->id ()
148- ->get ($ id );
149+ return ($ this ->cachedFlattenedPagesById ??= $ this ->flattenedPages ()->keyBy ->id ())->get ($ id );
149150 }
150151
151152 public function findByEntry ($ id )
152153 {
153- return $ this ->flattenedPages ()
154- ->filter ->reference ()
155- ->keyBy ->reference ()
156- ->get ($ id );
154+ return ($ this ->cachedFlattenedPagesByReference ??= $ this ->flattenedPages ()->filter ->reference ()->keyBy ->reference ())->get ($ id );
155+ }
156+
157+ public function entryOrder ($ reference )
158+ {
159+ return ($ this ->cachedFlattenedPageOrder ??= $ this ->flattenedPages ()->map ->reference ()->flip ())->get ($ reference );
157160 }
158161
159162 public function save ()
@@ -163,8 +166,10 @@ public function save()
163166 }
164167
165168 $ this ->cachedFlattenedPages = null ;
169+ $ this ->cachedFlattenedPagesById = null ;
170+ $ this ->cachedFlattenedPagesByReference = null ;
171+ $ this ->cachedFlattenedPageOrder = null ;
166172
167- Blink::forget ('collection-structure-flattened-pages-collection* ' );
168173 Blink::forget ('collection-structure-tree* ' );
169174
170175 $ this ->repository ()->save ($ this );
0 commit comments