-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
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
Closure inside getStateUsing() called 3 times per row #14852
Comments
Hey @btxtiger! We're sorry to hear that you've hit this issue. 💛 However, it looks like you forgot to fill in the reproduction repository URL. Can you edit your original post and then we'll look at your issue? We need a public GitHub repository which contains a Laravel app with the minimal amount of Filament code to reproduce the problem. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private / confidential, since we want a link to a separate, isolated reproduction. That would allow us to download it and review your bug much easier, so it can be fixed quicker. Please make sure to include a database seeder with everything we need to set the app up quickly. |
Thank you for providing reproduction steps! Reopening the issue now. |
i think you should use formatStateUsing instead of getStateUsing() |
@Cybrarist this does not work, since the state of the column should be any query or value (probably also a result of an HTTP request, Cache, other service, ...), and not dependant on a model column. |
@btxtiger oh ok, i get what you mean, then why not doing it like the following $table->modifyQueryUsing(function (Builder $query) {
$query->withCount('permissions');
}) and then you use 'permissions_count' in your TextColumn. |
@Cybrarist yes this would be a workaround for this specific example, but would not solve the actual problem. Tables\Columns\TextColumn::make('permission_granted')
->label('Permissions')
->badge()
->getStateUsing(function (User $user) {
return Http::get('https://dummy-auth-provider.com/api/check-permissions', ['uuid' => $user->uuid])
->json('permissions_granted') ? 'Granted' : 'Not Granted';
}); In this case, the closure is still executed 3 times, and thus make 3 https requests * number of rows, for 1 page load |
Seems a very bad idea to get the state of a column by doing an HTTP call for each one. |
Yeah, but still not targeting the issue. The issue is 3 redundant calls of a function where only one should be. Filament 3 became so much slower (less snappy) than v2, and I suspect this is one issue |
have the same problem here |
Package
filament/tables
Package Version
v3.2.124
Laravel Version
v11.33.2
Livewire Version
default
PHP Version
8.3.13
Problem description
When using
->getStateUsing()
to fill a column with a custom value, the Closure seems to be called 3 times per row!If this closure contains a custom query, this will lead to triple query execution per row!
Expected behavior
The Closure should be executed once on page load
Steps to reproduce
Example Column:
Reproduction repository (issue will be closed if this is not valid)
https://github.com/btxtiger/filament-getstateusing-bug-14852
Relevant log output
No response
Donate 💰 to fund this issue
The text was updated successfully, but these errors were encountered: