F
Filament4mo ago
btx

getStateUsing() called 3 times on first load

Hey there, I just investigated some performance issues and noticed that each table that uses getStateUsing() has this function 3 times called on loading the table. So each query inside gets also executed 3 times! Why? Simple Example:
Tables\Columns\TextColumn::make('products')
->label('Products')
->badge()
->getStateUsing(function (Domain $domain) {
\Log::debug('DomainResource::table::getStateUsing');
return $domain->products()->count();
})
,
Tables\Columns\TextColumn::make('products')
->label('Products')
->badge()
->getStateUsing(function (Domain $domain) {
\Log::debug('DomainResource::table::getStateUsing');
return $domain->products()->count();
})
,
No description
13 Replies
btx
btxOP4mo ago
Since I think now it is a bug after some hours of investigation, I reported this on GitHub https://github.com/filamentphp/filament/issues/14852
GitHub
Query inside getStateUsing called 3 times per row · Issue #14852 · ...
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 cus...
ericmp
ericmp4mo ago
@btx not sure if the problem is that u r making a query for each row to get the products count https://filamentphp.com/docs/3.x/tables/columns/relationships#counting-relationships
Tables\Columns\TextColumn::make('products_count')->counts('products')
Tables\Columns\TextColumn::make('products_count')->counts('products')
btx
btxOP4mo ago
Yea this would solve to problem for this specific example, but not when requiring any specialized query oder calculation for the colum, since the Closure is still called 3 times
ericmp
ericmp4mo ago
then idk, it may be debugbar
btx
btxOP4mo ago
its also replicateable when logging the calls to log file
ericmp
ericmp4mo ago
when u tested it, u disabled debugbar?
DEBUGBAR_ENABLED=false # .env
DEBUGBAR_ENABLED=false # .env
btx
btxOP4mo ago
I just checked with disabled debugbar, just with file logging, still 3 calls logged. I have a slight suspicion that this might be one of the reasons why the overall performance of v3 has become so much worse compared to v2. I just upgraded to M4 Pro, where I can't notice the lags anymore. But performance of v3 wasn't satisfying on my old 2019 MBP and i5-11400 desktop, and also its not in production.
ericmp
ericmp4mo ago
ohh, then im not sure. it may be yeah
raheel3031
raheel30314mo ago
What does this domain resource do?
btx
btxOP4mo ago
just shows the domains table
raheel3031
raheel30314mo ago
Yeah but are those sales channels??
btx
btxOP4mo ago
u mean some kind of laravel sales channels? no just a list of domains and products
raheel3031
raheel30314mo ago
Yes. Ah OK. I am looking to build sales channels. So basically use the same filament admin panel for multiple sales channels

Did you find this page helpful?