We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First of all, great plugin! Thanks for your work!
I noticed that queries in PageBlocks are fired every time you visit a page. Take for example this block:
PageBlocks
public static function getBlockSchema(): Block { return Block::make('my-block') ->schema([ Select::make('users') ->options(User::pluck('name', 'id')) ]); } public static function mutateData(array $data): array { return array_merge($data, [ 'users' => Cache::remember('my_block_users', 60, function () use ($data) { return User::find($data['users']); }), ]); }
When visiting the page, the mutated data is cached but the query for theSelect (User::pluck('name', 'id')) field is still running every time.
Select
User::pluck('name', 'id')
Cheers, Martin
The text was updated successfully, but these errors were encountered:
Ok, so investigating this further... in abstract class PageBlock
abstract class PageBlock
public static function getName(): string { return static::getBlockSchema()->getName(); }
is called which causes the queries to be run. For now, I can get around it by implementing getName() in each of my blocks and just returning a string.
getName()
Sorry, something went wrong.
Passing a closure to ->options() in Select ensures, that it is evaluated only when needed
->options()
Select::make('users') ->options(fn () => User::pluck('name', 'id'))
Ohhh... good catch! :)
No branches or pull requests
First of all, great plugin! Thanks for your work!
I noticed that queries in
PageBlocks
are fired every time you visit a page. Take for example this block:When visiting the page, the mutated data is cached but the query for the
Select
(User::pluck('name', 'id')
) field is still running every time.Cheers, Martin
The text was updated successfully, but these errors were encountered: