Following almost exactly the guide here, I have an ‘Entries’ page with children from an SQLite database. The page model for this has a public children() method that does Db::select('entires') etc.
This is all working, but after deploying in a dokku container the Panel requests for these child pages are extremely slow. It can take over 5 seconds to get 20 records (response time varies a lot). The frontend routes are not affected, as far as I can tell. Locally (macos, using valet) the panel does not have these issues at all…
Has anyone had similar issues? Any suggestions on how to profile this slowdown?
sqlite should fetch the entries way faster than that. so you are right to assume there is something wrong somewhere.
please share the source code in the model. this will make it easier to help you.
since we are trying to debug something that happens in the panel usual vardumps dont help much. you could try appending timestamps for steps to a file like this in various places
<?php
use Kirby\Cms\Page;
use Kirby\Cms\Pages;
use Kirby\Database\Db;
use Kirby\Cms\Structure;
use Kirby\Filesystem\F;
class EntriesPage extends Page {
public function children () {
if ($this->children instanceof Pages) {
return $this->children;
}
$entries = [];
foreach (Db::select('entries') as $item) {
$data = json_decode($item->points());
foreach ($data as $key => $value) {
$data[$key] = (array) $value;
}
$points = new Structure($data, $this);
$entries[] = [
'slug' => $item->slug(),
'num' => $item->status() === 'listed' ? 0 : null,
'template' => 'entry',
'model' => 'entry',
'content' => [
'title' => $item->title() ?? 'New entry',
'name' => $item->name() ?? '',
'location' => $item->location() ?? '',
'text' => $item->text() ?? '',
'date' => $item->date() ?? '',
'points' => $points->toArray(),
'status' => is_null($item->status()) ? 'draft' : $item->status()
]
];
}
return $this->children = Pages::factory($entries, $this);
}
}
Adding in some hrtime() checks and I get these results:
---- get entries children()
806838 ns for Db::select(entries)
2643327 ns for entries loop
238411 ns for Pages::factory
But that request in the Panel took 9.24 seconds (!). The children() method is only called once though. These times are similar to what I get locally, it’s definitely held up somewhere else.
Any other steps that this request is going through that I could log?
Update: I tested this on dokkuv0.29.4, on a different server, and there are no problems with response times. I’m updating dokku on the machine I had issues with (from ~v0.21). Will report back once that’s done.
EDIT: the update to dokku did fix this. I’m curious why that is but don’t have time to figure it out haha.