Skip to content

Commit 41e434a

Browse files
committed
Improved nav() performance for non-editor reads
1 parent d09b820 commit 41e434a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

core/src/Models/Page.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public function menu() : DescendantsRelation
337337
*/
338338
public function nav( $level = 0 ) : \Aimeos\Nestedset\Collection
339339
{
340-
return ( clone $this->ancestors )->push( $this ) // @phpstan-ignore-line property.notFound
340+
return collect( $this->ancestors )->push( $this )
341341
->skip( $level )->first()
342342
?->subtree?->toTree()
343343
?? new \Aimeos\Nestedset\Collection();
@@ -416,13 +416,19 @@ public function subtree() : DescendantsRelation
416416
// restrict maximum depth to three levels for performance reasons
417417
$maxDepth = ( $this->depth ?? 0 ) + config( 'cms.navdepth', 2 );
418418

419-
$builder = $this->newScopedQuery()->with( 'latest' )
419+
$isEditor = \Aimeos\Cms\Permission::can( 'page:view', Auth::user() );
420+
421+
$builder = $this->newScopedQuery()
420422
->select( 'id', 'parent_id', '_lft', '_rgt', 'depth', 'name', 'title', 'tag', 'path', 'domain', 'lang', 'to', 'status', 'config' )
421423
->whereIn( 'depth', range( 0, $maxDepth ) )
422424
->defaultOrder()
423425
->setModel(new Nav());
424426

425-
if( !\Aimeos\Cms\Permission::can( 'page:view', Auth::user() ) )
427+
if( $isEditor ) {
428+
$builder->with( 'latest' );
429+
}
430+
431+
if( !$isEditor )
426432
{
427433
$table = $this->getTable();
428434

0 commit comments

Comments
 (0)