digest: Directly fetch recipient ids from the DB.

Instead of iterating over Subscriptions and creating the list of home view
recipients, the query now only fetches recipient IDs from the DB.
This commit is contained in:
Puneeth Chaganti
2019-03-03 11:39:32 +05:30
committed by Tim Abbott
parent 94649f58f2
commit cb5e9107f4
2 changed files with 5 additions and 6 deletions

View File

@@ -230,11 +230,10 @@ def handle_digest_email(user_profile_id: int, cutoff: float,
user_profile, [pm.message for pm in pms[:pms_limit]])
context['remaining_unread_pms_count'] = max(0, len(pms) - pms_limit)
home_view_recipients = [sub.recipient for sub in
Subscription.objects.filter(
user_profile=user_profile,
active=True,
in_home_view=True)]
home_view_recipients = Subscription.objects.filter(
user_profile=user_profile,
active=True,
in_home_view=True).values_list('recipient_id', flat=True)
stream_messages = all_messages.filter(
message__recipient__type=Recipient.STREAM,

View File

@@ -121,7 +121,7 @@ class TestDigestEmailMessages(ZulipTestCase):
with queries_captured() as queries:
handle_digest_email(othello.id, cutoff)
self.assertTrue(29 <= len(queries) <= 30)
self.assertTrue(24 <= len(queries) <= 25)
self.assertEqual(mock_send_future_email.call_count, 1)
kwargs = mock_send_future_email.call_args[1]