has_permission gets called twice #9072
Replies: 5 comments
-
Hello there! First of all, it will run the To optimize performance, consider caching your query based on the request and using it repeatedly instead of running a query on the database each time. Furthermore, please provide us with the details of your custom permission classes here. |
Beta Was this translation helpful? Give feedback.
-
Yes. In my case, I can use cache to prevent extra DB hit (actually I already have it). My point is, assume a I'm not trying to solve it in my project, as the solution for me simply can be a cache. I'm just looking for enhancement and having a better optimization. |
Beta Was this translation helpful? Give feedback.
-
I think you might have misunderstood the class "OR." class OperationHolderMixin:
def __and__(self, other):
return OperandHolder(AND, self, other)
def __or__(self, other):
return OperandHolder(OR, self, other)
def __rand__(self, other):
return OperandHolder(AND, other, self)
def __ror__(self, other):
return OperandHolder(OR, other, self)
def __invert__(self):
return SingleOperandHolder(NOT, self) The In the composed_permissions = IsAuthenticatedUserOwner | permissions.IsAdminUser
has_perm = composed_permissions().has_object_permission(request, None, None) It will execute This is the edited version: I understand what is happening here. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your suggestion. But I was more looking for a solution to fix it in DRF, not in my code. |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Beta Was this translation helpful? Give feedback.
-
Hi!
In drf==3.14, the has_object_permission code has changed in
OR
class in 4aea8dd.The problem is, we are calling has_permission twice here, and I have some queries in my custom permission class, in has_permission method. So for each request, my queries are running twice and it makes my API slow.
I'd love to fix it myself, but I couldn't achieve any good solution for preventing calling has_permission again.
Any idea ?
Beta Was this translation helpful? Give feedback.
All reactions