F
Filament4mo ago
Jonas

Duplicate navigationbadge query with multitenancy

Hey, I'm using getNavigationFeature() in a FilamentPHP multitenancy app, like this:
public static function getNavigationBadge(): ?string
{
$waitingTasksCount = CustomerTask::waitingOnCustomer()->count();
return $waitingTasksCount > 0 ? (string) $waitingTasksCount : null;
}
public static function getNavigationBadge(): ?string
{
$waitingTasksCount = CustomerTask::waitingOnCustomer()->count();
return $waitingTasksCount > 0 ? (string) $waitingTasksCount : null;
}
While investigating with Laravel Debugbar, I noticed that the query runs for every tenant the user has access to, which seems unnecessary. For example, if I, as a user, have access to 10 customers, each page load runs 10 queries to get the navigation badge for each customer—even though only the active tenant is displayed and needed. I also noticed that it queries navigation badges for another panel on each page load, leading to even more unnecessary queries. Is there a way to ensure it only runs the query for the selected tenant and only within the same panel or is it a config issue on my end?
3 Replies
Jonas
JonasOP4mo ago
Hey, I'm using getNavigationFeature() in a FilamentPHP multitenancy app, like this:
public static function getNavigationBadge(): ?string
{
$waitingTasksCount = CustomerTask::waitingOnCustomer()->count();
return $waitingTasksCount > 0 ? (string) $waitingTasksCount : null;
}
public static function getNavigationBadge(): ?string
{
$waitingTasksCount = CustomerTask::waitingOnCustomer()->count();
return $waitingTasksCount > 0 ? (string) $waitingTasksCount : null;
}
While investigating with Laravel Debugbar, I noticed that the query runs for every tenant the user has access to, which seems unnecessary. For example, if I, as a user, have access to 10 customers, each page load runs 10 queries to get the navigation badge for each customer—even though only the active tenant is displayed and needed. I also noticed that it queries navigation badges for another panel on each page load, leading to even more unnecessary queries. Is there a way to ensure it only runs the query for the selected tenant and only within the same panel?
Arshavir
Arshavir3mo ago
Hey, is that issue was solved?
Jonas
JonasOP3mo ago
No, haven't found a fix for it

Did you find this page helpful?