kirby icon indicating copy to clipboard operation
kirby copied to clipboard

Form Class is loading queries (too?) eagerly causing (unnecessary) performance bottleneck

Open bnomei opened this issue 2 years ago • 4 comments

Describe the bug
Form class loads data even if it may be never used. it dataset is very big this causes a hugh delay for on each request. This is a common scenario in both autoid and boost plugin and currently make adding pages beyond 20k index impossible within 30sec timeout.

https://github.com/getkirby/kirby/blob/efe24a6ef4ad61010428b1cb725f8f97a633ff82/src/Cms/PageActions.php#L459

To Reproduce

  1. create a lot of pages of template human

  2. create a collection that does return a site->index()

<?php

return function () {
    return site()->index()->filterBy('template', 'human');
};
  1. create a page blueprint with a field with a multiselect query
# other fields
human:
  type: multiselect
  options: query
  max: 1
  query:
    fetch: kirby.collection('humans') # this does a site index -> filter
    text: "{{ page.title }}"
    value: "{{ page.id }}"
  1. create a single or a batch of new human page programmatically.
  2. the query will be executed in php code even it is most likely only used in api/kql/panel.

Expected behavior
the query should only be executed in context of api/kql/panel or when called explicitly in php.

Kirby Version
3.5.7 and 3.6.0-beta.1

bnomei avatar Oct 03 '21 17:10 bnomei

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Aug 10 '22 10:08 stale[bot]

dear bot. this issue has not been resolved. please keep it open.

bnomei avatar Aug 11 '22 08:08 bnomei

I think we should revisit what you wrote in "expected behavior": If we can find a way to resolve the options less often and only when they are needed, this will increase performance by a lot, no matter if a cache is used or not.

lukasbestle avatar Aug 27 '22 20:08 lukasbestle

We have started refactoring our blueprint and form classes. Would be best to tackle this, once that's done.

distantnative avatar Sep 20 '22 13:09 distantnative