Multi-tenancy tenantMenu performance (query count)
I've noticed that when the tenant menu is enabled to display all tenants a user belongs to, and the list of tenants is big, Filament performs a permission check (via a policy) for each resource across all tenants. This results in a significant number of unnecessary queries, as permissions should only be checked for the current tenant. Any reasons why this happens? and if there's a way to optimize or avoid this behavior?
3 Replies
Not sure if this is the same thing, but this helped me reduce the queries a lot: https://fxtwitter.com/neverything/status/1811662682745180510
π 4 β€οΈ 10 ποΈ 816
FxTwitter / FixupX
Silvan Hagen β‘οΈ (@neverything)
Filament Tip: Save Some Queries π
The tenant switcher builds the entire navigation for each tenant just to get the first URL. This can lead to unnecessary queries, especially with complex menus and count badges.
Here's a way to build the full menu only for the current tenant:
Will give it a try, thanks a lot! π
Let me know how it goes, I'm using it in production now and it has reduced the queries a lot.