Giter VIP home page Giter VIP logo

Comments (9)

lucabezerra avatar lucabezerra commented on May 16, 2024

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.

filipeximenes avatar filipeximenes commented on May 16, 2024

@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.

kheshav avatar kheshav commented on May 16, 2024

Hello @filipeximenes , thanks for your feedback. I have made a pull request regarding the Issue, PR 82

#82

The Fix solved the issues of duplicate queries on my side. :)

Please check and Merge if so required.

Thanks.

from django-role-permissions.

aldookware avatar aldookware commented on May 16, 2024

I there a solution to this problem?

from django-role-permissions.

filipeximenes avatar filipeximenes commented on May 16, 2024

@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.

powderflask avatar powderflask commented on May 16, 2024

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.

powderflask avatar powderflask commented on May 16, 2024

Please see PR #93 for my ideas for resolving this.

from django-role-permissions.

filipeximenes avatar filipeximenes commented on May 16, 2024

Thanks for the great work @powderflask!

from django-role-permissions.

filipeximenes avatar filipeximenes commented on May 16, 2024

Released on PyPI as version 2.2.1

from django-role-permissions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.