Duplicate queries with navigation badges + multi-tenancy

Hello, I'm trying to debug a duplicate query issue and see if this is intended behaviour or not. Whenever I enable navigation badges on a resource, there seems to be two duplicate requests for every team/group the user is part of.
protected static ?string $model = Video::class;

public static function getNavigationBadge(): ?string
{
return static::$model::count();
}

public static function getNavigationBadgeColor(): ?string
{
return 'success';
}
protected static ?string $model = Video::class;

public static function getNavigationBadge(): ?string
{
return static::$model::count();
}

public static function getNavigationBadgeColor(): ?string
{
return 'success';
}
No description
2 Replies
Cyborgmatt
Cyborgmatt10mo ago
if I apply the ApplyTenantScopes from the docs you can see that its being fired off for each team regardless of which one you have active
select count(*) as aggregate from `videos` where `videos`.`channel_id` in (1)
460μs
/app/Filament/Resources/VideoResource.php:37
select count(*) as aggregate from `videos` where `videos`.`channel_id` in (1)
390μs
/app/Filament/Resources/VideoResource.php:37
select count(*) as aggregate from `videos` where `videos`.`channel_id` in (2)
390μs
/app/Filament/Resources/VideoResource.php:37
select count(*) as aggregate from `videos` where `videos`.`channel_id` in (2)
340μs
/app/Filament/Resources/VideoResource.php:37
select count(*) as aggregate from `videos` where `videos`.`channel_id` in (1)
460μs
/app/Filament/Resources/VideoResource.php:37
select count(*) as aggregate from `videos` where `videos`.`channel_id` in (1)
390μs
/app/Filament/Resources/VideoResource.php:37
select count(*) as aggregate from `videos` where `videos`.`channel_id` in (2)
390μs
/app/Filament/Resources/VideoResource.php:37
select count(*) as aggregate from `videos` where `videos`.`channel_id` in (2)
340μs
/app/Filament/Resources/VideoResource.php:37
Im still not sure why each one is being fired off twice either
Jeff
Jeff9mo ago
Just curious if you solved this? I just looked at the DebugBar and see the same thing. Rather ineffecient. Trying to run the query as 'return Filament::getTenant()->users->count();' causes a warning about n+1 and eager loading, which seems odd. @Cyborgmatt From my testing, it seems to do this on first load for all the Teams/Tenants the user belongs to. And then caches it.