Virtual pages lead to infinite loop in panel

I have virtual pages coming from a sqlite database that worked in v4 but in v5 the panel goes into an infinite loop resulting in a php memory error.

There is a limit in the children() method and a limit in the blueprint but I still end up in an infinite loop.
Any tips for getting this to work?

Maybe post your code. We are using virtual pages with v5 without issues. Although, need to check the Panel behavior.

The parent:

use Kirby\Cms\Page;
use Kirby\Cms\Pages;
use Kirby\Database\Db;
use Kirby\Http\Url;

class VideosPage extends Page {
  public function children(): Pages {
    
    $path = Url::current();
    if (Str::matches($path, '/\/pages\/*/')) {
      if ($this->children instanceof Pages) {
        return $this->children;
      }

      $profiles = Db::table('video')->all();

      $children = [];
      foreach ($profiles as $row) {
        $content = [
                    'title'         => $row->title,
                    'description'   => $row->description,
                    'category'      => $row->category,
                    'platform'      => $row->platform,
                    'status'        => $row->status == 1 ? 'unlisted' : 'null',
                    'created'       => $row->created,
                    "vimeoid"       => $row->vimeoid,
                    "duration"	    => $row->vimeoduration,
                    "vimeothumbnail"=> $row->vimeothumbnail,
                    "vimeostatus"	  => $row->vimeostatus
        ];

        $children[] = [
          'slug'     => $row->id,
          'template' => 'video',
          'model'    => 'video',
          'translations' => [
            'en' => [
                'code' => 'en',
                'content' => $content
            ],
            'nl' => [
                'code' => 'nl',
                'content'  => $content
            ]
          ]
        ];
      }

      return $this->children = Pages::factory($children, $this);
    } else {
      return new Pages([]);
   }
  }
}

the children:

<?php

use Kirby\Cms\Page;
use Kirby\Content\Content;
use Kirby\Database\Db;

class VideoPage extends Page {

public function changeSlug(string $slug, string|null $languageCode = null): static
{
//don't change this, the slug is the id.
return $this;
}

protected function changeStatusToDraft(): static
{
$data['status'] = '0';

if ($profile = Db::first('video', '*', ['id' => $this->slug()])) {
Db::update('video', $data, ['id' => $this->slug()]);
}

return $this;
}

protected function changeStatusToUnlisted(): static
{
if ($this->status() === 'unlisted') {
return $this;
}

$data['status'] = 1;

if ($profile = Db::first('video', '*', ['id' => $this->slug()])) {
Db::update('video', $data, ['id' => $this->slug()]);
}

// $this->resortSiblingsAfterUnlisting();

return $this;
}

public function delete(bool $force = false): bool
{
return Db::delete('video', ['id' => $this->slug()]);
}

public function isDraft(): bool
{
return ($this->content()->status() == 'unlisted') === false;
}

public function writeContent(array $data, string|null $languageCode = null): bool

{
$data['status'] = ($data['status'] == 'unlisted' ? 1:0);
if ($profile = Db::first('video', '*', ['id' => $this->slug()])) {
return Db::update('video', $data, ['id' => $this->slug()]);
} else {
$new['id'] = $this->slug();
return Db::insert('video', $new);
}
}

}

/api/pages/videos/sections/pages?

It crashes on the pages section. I have tried just returning an empty Pages([]) but then it gives a 500 followed by a 401.

What I’m wondering is what this condition is doing there.

That is there to stop the frontend creating page objects for these 15000 pages.
Worked like a charm in v4.
We only use them as pages in the panel.