mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 07:39:16 +02:00
Removed 2 DB queries per request when user is authenticated
This commit is contained in:
parent
49e1bec7b9
commit
67de32ccc2
2 changed files with 18 additions and 1 deletions
17
api/funkwhale_api/users/auth_backends.py
Normal file
17
api/funkwhale_api/users/auth_backends.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from django.contrib.auth import backends, get_user_model
|
||||
|
||||
|
||||
class ModelBackend(backends.ModelBackend):
|
||||
def get_user(self, user_id):
|
||||
"""
|
||||
Select related to avoid two additional queries
|
||||
"""
|
||||
try:
|
||||
user = (
|
||||
get_user_model()
|
||||
._default_manager.select_related("actor__domain")
|
||||
.get(pk=user_id)
|
||||
)
|
||||
except get_user_model().DoesNotExist:
|
||||
return None
|
||||
return user if self.user_can_authenticate(user) else None
|
Loading…
Add table
Add a link
Reference in a new issue