F
Filament2d 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
7 Replies
btx
btxOP21h 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
ericmp20h 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
btxOP19h 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
ericmp19h ago
then idk, it may be debugbar
btx
btxOP18h ago
its also replicateable when logging the calls to log file
ericmp
ericmp18h ago
when u tested it, u disabled debugbar?
DEBUGBAR_ENABLED=false # .env
DEBUGBAR_ENABLED=false # .env
btx
btxOP17h 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.
Want results from more Discord servers?
Add your server