Multi-tenancy -> Navigation Badge count is querying for all tenants instead of just selected tenant.
Hi Guys, I have multi-tenancy configured with global scopes so the navigation badge count is showing the correct value, however if we have an admin who can access many tenants we run into time outs or extremely long loads, checking debug bar we can see that the system is trying to query count for each tenant the user has access to instead of just the currently selected tenant.
Fyi - we also have the below on the resource
public static function getNavigationBadge(): ?string
{
$tenant = Filament::getTenant();
return static::getModel()::where('cw_customer_id', $tenant->cw_id)->count();
}
Any suggestions on this one?
7 Replies
It shouldn't be really as the get tenant should only get the current tenant, not all tenants.
you could set the current_tenant_id on the user model however, and ensure your don't cal the tenant.
But you know... the tenant menu I found was very slow naturally and improved it with this view add to: /resources/views/vendor/filament-panels/components/
Dude! you're a legend 🙂 . I dont know what exactly in your modified menu fixes the issue but its working great now with no additional queries and its very quick
You are welcome! The issue is how we get the menu items, we get the tenant then check all the resources against each tenant, opposed to the current tenant.
But now your will also notice with the above view if your on X resource on tenant Y when you change to Tenant Z you will stay on X resource if it's available in this Tenants ACL 😉
yes i did notice, will play around with the new menu a bit to see other changes
@toeknee hey man, just wanted to let you know of a strange side affect from the new side bar.
If i open the side bar and scroll down a bit and then close the side bar (without changing tenants) and then i click on a side menu item such as Users or Dashboard, it changes to a random tenant.
any idea why this might be? i can share a recording if you want
Yeah screen record it, that shouldn’t happen as the tenant is defined within the url of each tenant. Only thoughts are you have tenant restricted items and we try to go to one but the tenant cannot access it
Hey man, here is a quick screen recording, i start on customer with ID 250, i open the tenant switcher and scroll down a bit, i do not click on another tenant but instead click on empty space on the right to close the menu, i then click on my company to reload the page and the customer changes to 20155
I actually have a feeling your tenancy menu didn't disappear properly and you clicked a hidden link? Can you inspect the page and see that the link shows on hover?