From bb56f0ec0e2af22c4cd990e2dd9830092af0fa27 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 13 Nov 2020 11:30:59 +0000 Subject: [PATCH] minor: Move get_stream_map to module level. This is a pure code move. --- zerver/lib/digest.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/zerver/lib/digest.py b/zerver/lib/digest.py index 96ab15b34b..7f2faec598 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[int user_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)