-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Deprecation: improve Celery task db query #10414
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
Conversation
This commit excludes the users that already have an unread notification with this message. This is only to avoid performing db queries for users where our notification backend won't add a new notification anyways. This will improve the performance of this task making it to run faster (hopefully).
I found the slow query. It's because it passes 85k slugs into the query: readthedocs.org/readthedocs/projects/tasks/utils.py Lines 294 to 298 in dc08e98
|
Instead of passing 82k slugs on each query to get the user's projects, we perform a set() intersection in Python which is fast. This reduces the time for this query in a pretty noticeable way.
This will interfere with the logic for sending email notifications. We do want to send an email even if the user didn't read the onsite notification.
I tried this code in production and it's a lot faster than the previous implementation. Using Python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍
Definitely okay to have a slow query for this case, but I totally understand if it got too slow. And that query does seem very slow :)
The code is also pretty readable, and it's definitely preferable to have correctness over performance :)
This commit excludes the users that already have an unread notification with this message. This is only to avoid performing db queries for users where our notification backend won't add a new notification anyways. This will improve the performance of this task making it to run faster (hopefully).