Comments (9)
This is completely unrelated to the issue itself, but just a heads up, it seems that you've got a typo in your permission's name at if has_permission(user, "access_dasboard"):
:)
Someone should be looking at this issue and providing you a proper answer soon.
from django-role-permissions.
@kheshav thanks for reporting! Feel free to work on this performance improvement, I'm happy to assist you with the PR process!
The fix will be probably in this function: https://github.com/vintasoftware/django-role-permissions/blob/master/rolepermissions/permissions.py#L52
from django-role-permissions.
Hello @filipeximenes , thanks for your feedback. I have made a pull request regarding the Issue, PR 82
The Fix solved the issues of duplicate queries on my side. :)
Please check and Merge if so required.
Thanks.
from django-role-permissions.
I there a solution to this problem?
from django-role-permissions.
@aldookware hey did not have time to work on this yet. Feel free to make a PR if you'd like that
from django-role-permissions.
This can be a serious performance hit, which can't be resolved be simply pre-fetching related groups and permissions.
available_perm_status(user)
makes a query for EACH permission the user has. I have one 'dashboard' type view that checks about 20 object permissions, each of which might check 2-3 user permissions (e.g., access_any, access_own, etc.) and Users that typically have 10-20 permissions. When you do the math, that creates hundreds of redundant queries.
get_user_roles(user)
has a similar performance issue, but not nearly as severe and much easier to resolve.
Ideally, the solution to this issue would result in ZERO queries when the user object has groups and permissions pre-fetched, and TWO queries (one for roles and one for permissions) otherwise. I believe this means the solution must fetch all()
related groups / permissions, and do filtering in Python (https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.prefetch_related)
I have hacked in a solution that has the above properties and meets my needs. Will work on creating a simple test case that demonstrates the issue, and a PR with a more polished version of this solution.
Since this code does not introduce any observable API behaviour, I assume the only new test required will verify that no extra queries are generated?
from django-role-permissions.
Please see PR #93 for my ideas for resolving this.
from django-role-permissions.
Thanks for the great work @powderflask!
from django-role-permissions.
Released on PyPI as version 2.2.1
from django-role-permissions.
Related Issues (20)
- Queryset of all objects which a particular user may access? HOT 1
- Create Dynamically roles HOT 3
- sync_roles --reset_user_permissions taking too much time HOT 2
- permissions added to role are not assigned automatically to user HOT 1
- Does not work with transactions? HOT 2
- Creating roles dynamically HOT 1
- Different permission for DRF CRUD HOT 1
- User hierarchy and role inheritance HOT 1
- HasPermissionsMixin no multiple permission support in required_permission HOT 1
- Can I do this with this git project? HOT 4
- Can role classes be created dynamically? HOT 1
- Updating roles question HOT 1
- Giving user a role from the admin pages doesn't update permissions? HOT 1
- Permission case issues with CustomUser HOT 3
- sync_roles not updating permissions for each role. HOT 1
- Unnecessary dependency: django-discover-runner HOT 2
- Migrate from Travis to GitHub Actions
- Valid for Django 4.2 HOT 5
- Any plans on implementing `HasObjectPermissionsMixin`?
- sync_roles across multitenant app HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-role-permissions.