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
missed-emails-sending: Move email sending to separate… #3462
missed-emails-sending: Move email sending to separate… #3462
Conversation
3ce3b61
to
54b949c
Compare
Automated message from Dropbox CLA bot @kkanahin, it looks like you've already signed the Dropbox CLA. Thanks! |
54b949c
to
354165f
Compare
zerver/lib/notifications.py
Outdated
messages = Message.objects.filter(usermessage__user_profile_id=user_profile, | ||
id__in=message_ids, | ||
usermessage__flags=~UserMessage.flags.read) | ||
if not messages.exists(): | ||
return |
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.
I think this change adds an extra database query; why did you make the change?
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.
On the contrary, I've decrease queries quantity in this place. but yes it would be better to use boolean condition here for queryset.
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.
But don't we need to fetch the messages anyway later on, so we end up doing a database query for the boolean check and then a second to fetch the message IDs (if any were returned)? Whereas previously we did a single query unconditionally.
It is a cheaper query in the case that there are no remaining unread messages in the list, but that case is rare.
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.
@timabbott I've agreed with you in my previous comment :)
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.
you are right, we should remove exists from condition.
@kkanahin thanks for working on this! I just got a chance to review this. I think this implementation should work, but it looks like this takes an approach of putting the arguments to
it seems like the resulting system would be somewhat cleaner, since then the email sending queue could actually be potentially reused for other things that send lots of emails as well. What do you think about switching to the approach I suggested? |
I think we shouldn't put email data to the queue, cause it can overload rabbitmq server when we will send more than 500 emails. All emails data will go through the message queue. That's why I've made such implementation. |
I can switch to your implementation, it doesn't take a lot of time. And we can test performance. Should I do it @timabbott ? |
Yeah, maybe do the other approach in a new PR (saving this code in case we decide we want it?). I think performance won't be an issue; my guess is that the part before it starts trying to send an email is just a few ms (whereas sending email with authentication is usually a few 100ms, as part of anti-spam strategies from email providers), but you can test that in development (should be similar in production) to confirm. |
sure @timabbott Will do it in another branch. |
354165f
to
9495622
Compare
- Add new 'missedmessage_email_senders' queue for sending missed messages emails. - Add the new worker to process 'missedmessage_email_senders' queue. - Split aggregation missed messages and sending missed messages email to separate queue workers. - Adapt tests for sending missed emails to the new logic. Fixes zulip#2607
9495622
to
f2a8e11
Compare
I think the new version is cleaner, so closing this. |
… queue.
to separate queue workers.
Fixes #2607