Open twigs67 opened 5 years ago
I figured out why there are so many queries...
//Role.js
async getPermissions () {
const permissions = await this.permissions().fetch()
return permissions.rows.map(({ slug }) => slug)
}
If a user has 40+ permissions, this is hitting the database 40+ times. Perhaps a more efficient route would be to make use of Adonis.pivotTable()?
you can check my fork where I did some optimizations to how the plugin query permissions and roles https://github.com/hadihallak/adonis-acl
i've changed it so that instead of it querying data everytime you use the middleware or use the can/is methods inside a controller, it will now use the prefetched permissions and roles already populated from the main "init" middleware.
Nice job! Althought a great package, it definitely needed some optimization. If I get some free time, I'll allow the package to cache permissions/roles to limit hits on the db. Thanks for this!
On Wed, Dec 26, 2018 at 1:36 PM Abdulhadi Hallak notifications@github.com wrote:
you can check my fork where I did some optimizations to how the plugin query permissions and roles https://github.com/hadihallak/adonis-acl
i've changed it so that instead of it querying data everytime you use the middleware or use the can/is methods inside a controller, it will now use the prefetched permissions and roles already populated from the main "init" middleware.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/enniel/adonis-acl/issues/26#issuecomment-450006410, or mute the thread https://github.com/notifications/unsubscribe-auth/AO9K-KGJ3m8kRpACde49mYcgG6i8hIX9ks5u88GTgaJpZM4Y0dVe .
@twigs67 I would just do something like this:
return await Role.query() .where("id", id) .with("permissions") .fetch();
Does that work for your use case?
@jacobwise I do not know if this works for @twigs67, but for me it took a user and needed to load their documents with their permissions this works, thanks
@hadihallak can you send a PR with your improvements?
Does no any fix from 2018 in this repo?
Project is apparently abandoned.
Hello,
I'm not sure if I'm doing something wrong or this is by design, but when the application initially loads the system is making over 70+ queries on permissions/permission_role/role tables.
Thanks