From 5cb05e6a227c3305743e002ec3a2d39f4807149a Mon Sep 17 00:00:00 2001 From: Mike VanDenburgh Date: Mon, 6 Nov 2023 17:59:48 -0500 Subject: [PATCH] Simplify query --- dandiapi/api/views/dandiset.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/dandiapi/api/views/dandiset.py b/dandiapi/api/views/dandiset.py index c87c8b62a..3c3d9e881 100644 --- a/dandiapi/api/views/dandiset.py +++ b/dandiapi/api/views/dandiset.py @@ -374,13 +374,11 @@ def users(self, request, dandiset__pk): def get_user_or_400(username): try: - return User.objects.alias( - social_account_username=Subquery( - SocialAccount.objects.filter(user_id=OuterRef('id')).values( - 'extra_data__login' - )[:1] - ) - ).get(social_account_username=username) + return ( + SocialAccount.objects.select_related('user') + .get(extra_data__login=username) + .user + ) except ObjectDoesNotExist: try: return User.objects.get(username=username)