Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
minor: Move get_stream_map to module level.
Steve Howellbb56f0ec0e2a
diff --git a/zerver/lib/digest.py b/zerver/lib/digest.pyindex 96ab15b34bd..7f2faec5987 100644--- a/zerver/lib/digest.py+++ b/zerver/lib/digest.py@@ -218,6 +218,21 @@ def gather_new_streams(user_profile: UserProfile,def enough_traffic(hot_conversations: str, new_streams: int) -> bool:return bool(hot_conversations or new_streams)+def get_stream_map(user_ids: List[int]) -> Dict[int, Set[int]]:+ rows = Subscription.objects.filter(+ user_profile_id__in=user_ids,+ recipient__type=Recipient.STREAM,+ active=True,+ is_muted=False,+ ).values('user_profile_id', 'recipient__type_id')++ # maps user_id -> {stream_id, stream_id, ...}+ dct: Dict[int, Set[int]] = defaultdict(set)+ for row in rows:+ dct[row['user_profile_id']].add(row['recipient__type_id'])++ return dct+def bulk_get_digest_context(users: List[UserProfile], cutoff: float) -> Dict[int, Dict[str, Any]]:# Convert from epoch seconds to a datetime object.cutoff_date = datetime.datetime.fromtimestamp(int(cutoff), tz=datetime.timezone.utc)@@ -226,21 +241,6 @@ def bulk_get_digest_context(users: List[UserProfile], cutoff: float) -> Dict[intuser_ids = [user.id for user in users]- def get_stream_map(user_ids: List[int]) -> Dict[int, Set[int]]:- rows = Subscription.objects.filter(- user_profile_id__in=user_ids,- recipient__type=Recipient.STREAM,- active=True,- is_muted=False,- ).values('user_profile_id', 'recipient__type_id')-- # maps user_id -> {stream_id, stream_id, ...}- dct: Dict[int, Set[int]] = defaultdict(set)- for row in rows:- dct[row['user_profile_id']].add(row['recipient__type_id'])-- return dct-stream_map = get_stream_map(user_ids)recently_modified_streams = get_modified_streams(user_ids, cutoff_date)