KFet Backends inherit from BaseKFetBackend
Users who authenticate via a KFetBackend got extra select related. It should save 2 db queries on each request for these users.
This commit is contained in:
parent
e5d19811e8
commit
3fa7754ff4
1 changed files with 17 additions and 2 deletions
|
@ -7,7 +7,22 @@ from .utils import get_kfet_generic_user
|
|||
User = get_user_model()
|
||||
|
||||
|
||||
class KFetBackend(object):
|
||||
class BaseKFetBackend:
|
||||
def get_user(self, user_id):
|
||||
"""
|
||||
Add extra select related up to Account.
|
||||
"""
|
||||
try:
|
||||
return (
|
||||
User.objects
|
||||
.select_related('profile__account_kfet')
|
||||
.get(pk=user_id)
|
||||
)
|
||||
except User.DoesNotExist:
|
||||
return None
|
||||
|
||||
|
||||
class KFetBackend(BaseKFetBackend):
|
||||
def authenticate(self, request):
|
||||
password = request.POST.get('KFETPASSWORD', '')
|
||||
password = request.META.get('HTTP_KFETPASSWORD', password)
|
||||
|
@ -20,7 +35,7 @@ class KFetBackend(object):
|
|||
return None
|
||||
|
||||
|
||||
class GenericTeamBackend(object):
|
||||
class GenericTeamBackend(BaseKFetBackend):
|
||||
def authenticate(self, username=None, token=None):
|
||||
valid_token = GenericTeamToken.objects.get(token=token)
|
||||
if username == 'kfet_genericteam' and valid_token:
|
||||
|
|
Loading…
Reference in a new issue