Remember this - Caching in Kirby

my boost plugin is not needed but might improve performance non the less.

this is what i would do… use an cached array. to avoid calling the index on multiple requests by the panel (the static wont help there, just within a single request) i would use a cache. personally i suggest using my lapse plugin because its syntax is quiet simple to create caches. a similar technique is used in boost for its kv collections.

link:
  type: multiselect
  max: 1
  options: query
  required: true
  query:
    fetch: kirby.collection('cachedIndexKeyValues')
    value: {{ arrayItem.value }}
    text: {{ arrayItem.text }}

site/collections/cachedIndexKeyValues.php

// use a static cache (multiple calls in same request)
return fn() => lapseStatic(__FILE__, function () {
    // use a 1 minute cache to store props for the multiselect field
   // avoid crawling index for 1 minute
    $data = lapse(__FILE__, function () {
        return site()->index(true)->toArray(function ($page) {
            return [
                'text' => $page->title() . ' - ' . $page->uri(),
                'value' => $page->autoid(),
            ];
        });
    }, 1); // 1 minute

    // return a kirby Obj to make the panel multiselect arrayItem work
    return array_map(fn($item) => new \Kirby\Toolkit\Obj($item), $data);
});
1 Like