filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
19.29k stars 2.96k forks source link

Unnecessary Policy Checks with Multi Tenancy #14830

Open wannesmatthys opened 4 hours ago

wannesmatthys commented 4 hours ago

Package

filament/filament

Package Version

v3.2.124

Laravel Version

v11.32.0

Livewire Version

v3.5.12

PHP Version

PHP 8.3.3

Problem description

When we have multiple teams, filament always does a check of the policies for every team instead of only for the current team. In large applications with lots of teams this can slow down the application a bit.

So for example, here I have a simple filament dashboard with only one Resource "Posts". If I have one Team, this is the output for the Gates in debugbar. image

When registering a new Team, it loads the policies (of the navigation?) multiple times.

With 2 teams: image

With 3 teams: image

And so on

Expected behavior

It should only load the correct policies once.

Steps to reproduce

Clone the repository, create a couple of teams and check the debugbar. Everytime you add a new team, the "Gates" will increase in debugbar.

Reproduction repository (issue will be closed if this is not valid)

https://github.com/wannesmatthys/filament-gates-reproduction

Relevant log output

No response

Donate 💰 to fund this issue

Fund with Polar

wannesmatthys commented 3 hours ago

I'm debugging this further, and apparently to generate all the tenant URL's (see photo), it calls

$this->navigationManager = new NavigationManager;
$navigation = $this->navigationManager->get();

in the file HasRoutes.php (line 194). This loads all navigation items (and policies) for every tenant.

Would there be another way to generate this URL maybe?

image