Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions drf_roles/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def __init__(self, **_kwargs):
def _call_role_fn(self, fn, *args, **kwargs):
"""Attempts to call a role-scoped method"""
try:
role_name = self._get_role(self.request.user)
role_fn = "{}_for_{}".format(fn, role_name)
if not getattr(self, '_role_name', None):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try using lru_cache from functools python module for result cache

https://docs.python.org/3/library/functools.html#functools.lru_cache

self._role_name = self._get_role(self.request.user)
role_fn = "{}_for_{}".format(fn, self._role_name)
return getattr(self, role_fn)(*args, **kwargs)
except (AttributeError, RoleError):
return getattr(super(RoleViewSetMixin, self), fn)(*args, **kwargs)
Expand Down