kiritokatklian / nova-permission

A Laravel Nova tool for Spatie's laravel-permission library
https://novapackages.com/packages/vyuldashev/nova-permission
MIT License
68 stars 14 forks source link

Extremely slow when viewing roles. #36

Open amanpatel opened 1 month ago

amanpatel commented 1 month ago

https://github.com/kiritokatklian/nova-permission/blob/c8d16c7601fcbd19e3c6959ec765409690e91aed/src/PermissionBooleanGroup.php#L30

We have about 200 permissions in our system and about 19 roles, and this line of code is causing extremely slow responses when trying to load the roles list page. So when viewing the roles page, it has to fetch about 4000 Permission models, and while the database is pretty fast, the laravel model hydration is causing delays in app code.

In our system, only super-admins can view/manage permissions, so I am questioning why this code is needed. Can we remove this, or somehow make it optional during the field setup?

I can submit a PR if this works.

kiritokatklian commented 1 month ago

@amanpatel Saw your PR #37. I'm holding off on merging it since that looks more like a workaround than an actual fix. I'll keep it open for now, so feel free to point composer at it in the meantime to address your issue.

I myself have 319 permissions and 8 roles, and I noticed the load time is a bit slow too. I'll look into it and hopefully come up with an actual fix for the issue. If not then I'll merge the PR for the time being.

alexanderjoe commented 1 month ago

Queries Gate

I'm running into a similar situation with a BelongsTo relationship on a Nova model where the user Nova model has both RoleBooleanGroup and PermissionBooleanGroup.

It is causing n+1 to occur where I'm executing 4000+ queries and loading 14k models with 12k gate checks. If I remove the boolean groups it is significantly less.

After Removing

Not sure if this is a configuration issue on my end but it seems to be related.