From d403260e9b4a41d061f04d89a663e87792b9c188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 21 Jan 2019 21:59:50 +0200 Subject: [PATCH] Preload Profile.current_project, saves one query per request. --- hc/accounts/backends.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hc/accounts/backends.py b/hc/accounts/backends.py index 5485144e..9818ab81 100644 --- a/hc/accounts/backends.py +++ b/hc/accounts/backends.py @@ -6,7 +6,10 @@ class BasicBackend(object): def get_user(self, user_id): try: - return User.objects.select_related("profile").get(pk=user_id) + q = User.objects.select_related("profile", + "profile__current_project") + + return q.get(pk=user_id) except User.DoesNotExist: return None