Panel speed / cache?

sorry if is a numb question.

i need to acelerate de panel, i have 6500 pages with 26000 children (totaly).

can anybody point me in the right direction o give some suggestion? thanks a lot!

What is your page structure like?

TIP: be mindful of how you use the query syntax in blueprints. replace long running queries with custom page methods utilizing a custom cache (using lapse plugin etc).

hi, and thanks. i will investigate it!!

hi bnomei,

my intention is to speed up the panel pages section, i am usign a custom method. the section inisde the panel works, but is the same loading time using or not using Lapse plugin.

i have this code:

class autorizacionesPage extends Kirby\Cms\Page {

public function historial() {
    
    
    $collection = pages('afiliados')
            ->grandChildren()
            ->filterBy('intendedTemplate', 'in', ['autorizacion', 'consulta']);
    

          
$data = Bnomei\Lapse::io(
    $collection, // this will turn into a key taking modification date of all objects into consideration
    function () use ($collection) {
       return [
        
        
        'historiales' => $collection,
        
        
    ];
    }
);


$h = $data['historiales'];

    return $h;
  }


}

gaining performance does not work that way. you have to delay the creation of the pages collection to inside the call to lapse. so if there is no cache or it is expired the collection will be created anew.

<?php

class AutorizacionesPage extends Kirby\Cms\Page {

	public function historial(): Kirby\Cms\Pages
	{
	    
	    // speed up the time to fetch ids from an complex pages tree
		$data = Bnomei\Lapse::io(
		    'AutorizacionesHistorial',
		    function () {
			    $collectionForIds = pages('afiliados')
		            ->grandChildren()
		            ->filterBy('intendedTemplate', 'in', ['autorizacion', 'consulta']);

		             return [
		        	'historiales' => $collectionForIds, 
		    	     ];
	    	        }
			, 1 // expire in minutes. adjust to your needs.
		);

		// what exactly did this code save you?
		// probably not much.
		// your gain in performance mostly depends on how 
		// many files have be skipped when using the cache.

		// kirby is lazy loading data required when crawling
		// the file tree. it is NOT reading the content files that
		// do not match your template filter.
		// if you would do more complex stuff or modified checks
		// you would gain more.

		return $data['historiales'];
	}
}

i think lapse should be doing fine with serialization of the pages object but i have not tested that recently but i will.

if it does not work consider just storing the ids and rebuilding the collection yourself.

<?php

class AutorizacionesPage extends Kirby\Cms\Page {

	public function historial(): Kirby\Cms\Pages
	{
		$data = Bnomei\Lapse::io(
		    'AutorizacionesHistorial',
		    function () {
			    $collectionForIds = pages('afiliados')
		            ->grandChildren()
		            ->filterBy('intendedTemplate', 'in', ['autorizacion', 'consulta']);

		        return [
		        	'historiales' => $collectionForIds->keys(), // for pages: key == id 
		    	];
	    	}
			, 1 // expire in minutes. adjust to your needs.
		);
		
		// new pages collection
		$collection = new Pages(
			array_map(function($id) {
				return page($id); // get page foreach id
			}, $data['historiales'])
		);

		return $collection;
	}
}

@diezmilseres serialization does NOT work out-of-the-box. you need to recreate the pages collection yourself. but since kirby is clever enough to do that from an array of ids the code from above can be made shorter see <!--------.

<?php

class AutorizacionesPage extends Kirby\Cms\Page {

	public function historial(): Kirby\Cms\Pages
	{
		$data = Bnomei\Lapse::io(
		    'AutorizacionesHistorial',
		    function () {
			    $collectionForIds = pages('afiliados')
		            ->grandChildren()
		            ->filterBy('intendedTemplate', 'in', ['autorizacion', 'consulta']);

		        return $collectionForIds->keys(); // for pages: key == id  <!--------

	    	}
			, 1 // expire in minutes. adjust to your needs.
		);
		
		// new pages collection from array of ids <!--------
		return new Pages($data);
	}
}