Removed 2 DB queries per request when user is authenticated

merge-requests/552/head
Eliot Berriot 2019-01-04 13:52:36 +01:00
rodzic 49e1bec7b9
commit 67de32ccc2
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DD6965E2476E5C27
2 zmienionych plików z 18 dodań i 1 usunięć

Wyświetl plik

@ -327,7 +327,7 @@ SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
# AUTHENTICATION CONFIGURATION # AUTHENTICATION CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
AUTHENTICATION_BACKENDS = ( AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend", "funkwhale_api.users.auth_backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend", "allauth.account.auth_backends.AuthenticationBackend",
) )
SESSION_COOKIE_HTTPONLY = False SESSION_COOKIE_HTTPONLY = False

Wyświetl plik

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