mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	digest: Switch loop to early-abort for clarity.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							b555d3f553
						
					
				
				
					commit
					b9f72bdd68
				
			@@ -3,7 +3,7 @@ import functools
 | 
			
		||||
import heapq
 | 
			
		||||
import logging
 | 
			
		||||
from collections import defaultdict
 | 
			
		||||
from typing import Any, Collection, Dict, List, Set, Tuple
 | 
			
		||||
from typing import Any, Collection, Dict, Iterator, List, Optional, Set, Tuple
 | 
			
		||||
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.db import transaction
 | 
			
		||||
@@ -383,9 +383,12 @@ def bulk_handle_digest_email(user_ids: List[int], cutoff: float) -> None:
 | 
			
		||||
        context = context_map[user.id]
 | 
			
		||||
 | 
			
		||||
        # We don't want to send emails containing almost no information.
 | 
			
		||||
        if enough_traffic(context["hot_conversations"], context["new_streams_count"]):
 | 
			
		||||
        if not enough_traffic(context["hot_conversations"], context["new_streams_count"]):
 | 
			
		||||
            continue
 | 
			
		||||
 | 
			
		||||
        digest_users.append(user)
 | 
			
		||||
        logger.info("Sending digest email for user %s", user.id)
 | 
			
		||||
 | 
			
		||||
        # Send now, as a ScheduledEmail
 | 
			
		||||
        send_future_email(
 | 
			
		||||
            "zerver/emails/digest",
 | 
			
		||||
 
 | 
			
		||||
@@ -136,6 +136,23 @@ class TestDigestEmailMessages(ZulipTestCase):
 | 
			
		||||
            set(emailed_user_ids), {user_id for user_id in user_ids if user_id != hamlet.id}
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    @mock.patch("zerver.lib.digest.send_future_email")
 | 
			
		||||
    def test_enough_traffic(self, mock_send_future_email: mock.MagicMock) -> None:
 | 
			
		||||
        othello = self.example_user("othello")
 | 
			
		||||
        self.subscribe(othello, "Verona")
 | 
			
		||||
 | 
			
		||||
        in_the_future = timezone_now().timestamp() + 60
 | 
			
		||||
 | 
			
		||||
        bulk_handle_digest_email([othello.id], in_the_future)
 | 
			
		||||
        mock_send_future_email.assert_not_called()
 | 
			
		||||
 | 
			
		||||
        with mock.patch(
 | 
			
		||||
            "zerver.lib.digest.enough_traffic", return_value=True
 | 
			
		||||
        ) as enough_traffic_mock:
 | 
			
		||||
            bulk_handle_digest_email([othello.id], in_the_future)
 | 
			
		||||
            mock_send_future_email.assert_called()
 | 
			
		||||
            enough_traffic_mock.assert_called_once_with([], 0)
 | 
			
		||||
 | 
			
		||||
    @mock.patch("zerver.lib.digest.enough_traffic")
 | 
			
		||||
    @mock.patch("zerver.lib.digest.send_future_email")
 | 
			
		||||
    def test_guest_user_multiple_stream_sender(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user