Putting content in subfolders for performance


I am trying to use kirby for an event calendar. It should be able to deal with more than a thousand events. (once this pandemic is over…)
I have followed the advice to split up the events in a tree-like subfolder structure and went along with some advices I found here in the forum:

β”œβ”€β”€ 1_veranstaltungen
β”‚   β”œβ”€β”€ 2020
β”‚   β”‚   β”œβ”€β”€ 09
β”‚   β”‚   β”‚   β”œβ”€β”€ 202009041221_exhibition
β”‚   β”‚   β”‚   β”‚   └── event.txt
β”‚   β”‚   β”‚   └── 202009261400_otherevent
β”‚   β”‚   β”‚       └── event.txt
β”‚   β”‚   β”œβ”€β”€ 10
β”‚   β”‚   β”‚   └── 202010161900_ausstellung
β”‚   β”‚   β”‚       └── event.txt
β”‚   β”‚   └── 12
β”‚   β”‚       └── 202012030043_test-event-konzert
β”‚   β”‚           └── event.txt
β”‚   β”œβ”€β”€ _drafts
β”‚   β”‚   └── i-am-a-draft-event
β”‚   β”‚       └── event.txt
β”‚   β”œβ”€β”€ events.txt

So, the panel users creates a new event directly the main events page, all drafts are in a β€œgeneral” draft folder and only when the page status changes to β€˜listed’ a hook comes along and sorts them into the respective subfolder. And vice versa.

'hooks' => [
    'page.changeStatus:after' => function ($newPage, $oldPage) {
    	$page = $newPage;
    	if($page->template() == 'event' && $page->status() == 'listed') { /* unlisted status is not used here */
    		$year = $page->date_start()->toDate('Y');
    		$month = $page->date_start()->toDate('m');
    		$newdir = $page->parent()->contentFileDirectory() . '/' . $year . '/' . $month . '/' . $page->dirname() ; /* year/month/subfolder structure */
    		$olddir = $page->contentFileDirectory();
    		Dir::move($olddir, $newdir);
    	if($page->template() == 'event' && $page->status() == 'draft') {
    		$newdir = $page->parent()->parent()->parent()->contentFileDirectory() . '/_drafts/' . $page->dirname() ; /* general drafts folder directly under 1_events */
    		$olddir = $page->contentFileDirectory();
    		Dir::move($olddir, $newdir);  

I don’t have much experience with routes and altering the panel logic in general in Kirby, and so I would be glad if someone could point me in the right direction with these questions:

- Redirect: How to forward the panel user to the right page after is had been moved?
The current hook, of course, produces a The page cannot be found Error in the panel. But a go($newpage) command doesn’t work in the panel it seems. Any ideas? Couldn’t find a solution in the forum either, but maybe I was looking for the wrong thing.

- Panel View: How to visually hide this tree structure in the panel?
If I don’t want to bother the editors with navigating year+month folder structures, how could I make it this comfortable in the panel? I use the pagetables plugin, but as far as I understood, there is no virtual parent option in general: https://github.com/sylvainjule/kirby-pagetable/issues/54 Could this by filtered somehow?

Any help appreciated very much and in general thanks to this fantastic forum, it helped me already in so many ways!

PS: since the question of performance-related subfolder-structure pops up a few times in the forum, maybe this could also be a potential cookbook?

I’m not aware of a solution for the first problem. There is no way to redirect from the hook to the new page.

As regards the second question, you could use the pagesdisplay plugin with a query. That would free you from the limitations of having only one parent (at the price of sacrificing the possibilty of being able to add pages, so you definitely need a second section for the drafts (which probably makes sense anyway).

The Pagetable plugin is great, but doesn’t support queries but only a single parent (link the default pages section). If you want to keep the functionality of the Pagetable, you could create your own fork and add the query functionality.

Just an idea: I have never tested this, but I wonder if a page model that overrides the changeStatus method and not only changes the status but also moves the the page to its destination folder could work here instead of the hook.

thanks a lot, @texnixe!

i stumbled upon on pagetable plugin modification proposal in an old issue on github: https://github.com/sylvainjule/kirby-pagetable/issues/16
and it work well! so now pagetable is querying the published events properly from the tree structure and a separate pagetable is querying the drafts.

the page model idea sounds interesting, but since i haven’t worked with page models yet: what would be the benefit? what could a page model do, that a hook couldnt?

Well, the problem with the hook is that it doesn’t redirect to the moved page. My idea was that if it was possible to do this within the changeStatus method in a page model, the redirect would be automatic. But since I haven’t tested this, I cannot tell if that’s true or not.