techmatters / terraso-backend

A Django project that powers the backend of Terraso platform.
GNU Affero General Public License v3.0
21 stars 4 forks source link

feat: improve login response time by not synchronously downloading and re-uploading the user's profile image on every login request #1371

Closed shrouxm closed 2 weeks ago

shrouxm commented 1 month ago

Description

I did some quick and dirty log statement profiling of the backend, and it seems that the vast majority of the time spent by the backend during a login request is synchronously downloading the user's profile image and uploading it to S3.

We should do at least one of:

Either method would resolve the slow login, but I'm not sure which is more straightforward to implement at first glance.

Additional context

Specifically:

I don't have experience with launching async tasks in django, so not sure how big a lift that is. And I don't know if the profile image URL provides information to determine if it has changed or not. I'm not even sure if we need to be storing the profile images on our own backend or if we can just use the oauth provider's profile image URL as is.

paulschreiber commented 1 month ago

FYI @josebui

paulschreiber commented 1 month ago

Some notes on background tasks: https://agrahariyash.medium.com/asynchronous-task-queues-in-the-django-world-a5d9be407e18 https://realpython.com/asynchronous-tasks-with-django-and-celery/

knipec commented 1 month ago

Triage notes:

FYI @CourtneyLee333

josebui commented 1 month ago

Hey All, I don't have a lot of experience with async tasks in django but from what Paul posted seems possible, for me this seems like a 5 points task, maybe less depending on how easy it will be to configure the async task

DerekCaelin commented 1 month ago

Thanks, @josebui! - if it's alright I will put it in the August to-do list, with the expectation that it is a lower priority than the other tasks listed.

paulschreiber commented 2 weeks ago

This has been deployed to production.