Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize user fetching in TokenAuthentication #16

Closed
eshaan7 opened this issue May 17, 2021 · 1 comment · Fixed by #17
Closed

Optimize user fetching in TokenAuthentication #16

eshaan7 opened this issue May 17, 2021 · 1 comment · Fixed by #17
Labels
enhancement New feature or request

Comments

@eshaan7
Copy link
Owner

eshaan7 commented May 17, 2021

From django-silk profiling,

        if not auth_token.user.is_active:

is causing a query like:

SELECT "api_user"."id",
       "api_user"."password",
       "api_user"."last_login",
       "api_user"."is_superuser",
       "api_user"."username",
       "api_user"."first_name",
       "api_user"."last_name",
       "api_user"."email",
       "api_user"."is_staff",
       "api_user"."is_active",
       "api_user"."date_joined"
FROM "api_user"
WHERE "api_user"."id" = 1
LIMIT 21

this can be potentially be optimized using select_related.

@eshaan7
Copy link
Owner Author

eshaan7 commented May 17, 2021

Another idea could be a way by which user can configure the select_related field for request.user on the TokenAuthentication class.


Reference: https://stackoverflow.com/a/65924551/10534470

@eshaan7 eshaan7 added the enhancement New feature or request label May 17, 2021
eshaan7 added a commit that referenced this issue May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant