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?
1 Reply
Jonas
Jonas3w 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?
Want results from more Discord servers?
Add your server