0

I have a project developed with the roles and permissions package caffeinated/shinobi/ .

now to optimize its loading I added the package to detect the n + 1 error in queries and I realized that for every @can directive it executed a query.

so for each load it executes 120 queries since I have 120 @can verifications in my blade view, it is a horror, does anyone know how to fix it?

does anyone know how to solve it (didn't know what portion of code to add)?

view

@can('slug-permission')

            
@endcan
DarkFenix
  • 706
  • 1
  • 13
  • 34
  • This is not an N+1 problem. N+1 is when you want to load the relationships of multiple models and instead of loading them all in 1 query you load them all in N queries (one per model). Presumably here you only have 1 model and N relationships – apokryfos Jul 27 '20 at 07:00
  • @apokryfos that's what the package throws at me https://github.com/beyondcode/laravel-query-detector – DarkFenix Jul 27 '20 at 07:13
  • https://stackoverflow.com/questions/97197/what-is-the-n1-selects-problem-in-orm-object-relational-mapping if you need to load N relationships for a single user you have to do N queries. There is no avoiding that. The package you linked does not seem to care whether you have a single model or multiple models. It just detects the lazy loads – apokryfos Jul 27 '20 at 07:20

0 Answers0