Site Index slow

Hi,

I am developing an intranet-repository for videos and images organized by directory structure which kirby perfectly can work with. Naturally we already have quite a lot subpages.

I created a template for admins to check on newly created pages as well as to search all pages using datatables (https://www.datatables.net)

<?php $index = $site->find('clients')->index()->visible()->sortBy('modified', 'desc');?>

Everything works fine, only while the site is growing the indexing gets slower and slower.
Is there a better way to accomplish what I am doing here?

Best,
Chris

Indexing by the jQuery plugin or on the backend? If you mean that page load times get slower, the reason is probably having too many subpages in a page. Kirby is fine with many pages in general, but it’s difficult to work with many direct subpages.

Indexing is done by kirbys backend with $site->find('clients')->index(). After that I run a foreach loop to fill the jquery datatable. I was afraid that this is the reason the page is getting slow: Kirby has to run all subdirectories everytime the page is loaded. This is definitely an advantage of a dedicated database.

It may be the rendering portion of the response that is actually taking the most time, here— you could try paginating the results (->paginate(50)), then AJAXing in new ones, rather than rendering out what appears to be every page in the system.

This could be accomplished with a custom route, which hits a function that returns a JSON array, determined by a passed argument (probably a GET param). The Datatables plugin claims to support Ajax resources!

This would split the rendering into multiple chunks (actually, the server might not do any rendering at all, if the table rows are getting build in the browser), and make each chunk feel more responsive— I think…

Search is another beast entirely… You must look at every page. Google may have a service to handle this kind of thing.

It looks like I’m asking a similar question here:
http://forum.getkirby.com/t/php-performance-and-kirby/1178/1

One solution I have thought of (but not implemented yet) is to create a single “index” file - containging a big JSON object - that is pared down to the essentials. Kirby would update this index every time a change is made to the panel (using the new hooks feature, excited about this). In my case it would look something like:

$book_index = [];

foreach ($site->pages()->find('writers')->children()->children() as $book) {
	$book_array['url'] = $book->url();
        $book_array['uid'] = $book->uid();
	$book_array['author'] = $book->parent()->title();
	$book_index[] = $book_array;
}

$book_index_file = fopen($_SERVER["DOCUMENT_ROOT"] . '/assets/php/book_index.json', 'a+');
fwrite($book_index_file, serialize($book_index));
fclose($book_index_file);

That way, when I do a search, I don’t need Kirby to fire up all of its engines and parse through all of the subpages. Instead, I’m just looking at a single file, and search results would return only the relevant info: page title, page UID, and page URL.

I imagine that this JSON object (which would not be re-created every time you load the page, only after panel updates) would be easy to build a datatable with.

There may be smarter ways to do this. The Kirby API also has ways of working with databases, but I haven’t looked into it.