mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
refactor: Avoid "stream_id" on sub.
There was no need to put "stream_id" on the sub dictionary here. It's kinda annoying to introduce the little helper here, but I feel that's better than crufting up the sub data structure.
This commit is contained in:
@@ -5002,19 +5002,16 @@ def gather_subscriptions_helper(user_profile: UserProfile,
|
|||||||
if recip_id_to_stream_id.get(sub["recipient_id"])
|
if recip_id_to_stream_id.get(sub["recipient_id"])
|
||||||
]
|
]
|
||||||
|
|
||||||
# Hydrate sub_dicts with stream_id
|
def get_stream_id(sub: Subscription) -> int:
|
||||||
for sub in sub_dicts:
|
return recip_id_to_stream_id[sub["recipient_id"]]
|
||||||
recipient_id = sub["recipient_id"]
|
|
||||||
stream_id = recip_id_to_stream_id[recipient_id]
|
|
||||||
sub["stream_id"] = stream_id
|
|
||||||
|
|
||||||
stream_ids = {sub["stream_id"] for sub in sub_dicts}
|
traffic_stream_ids = {get_stream_id(sub) for sub in sub_dicts}
|
||||||
recent_traffic = get_streams_traffic(stream_ids=stream_ids)
|
recent_traffic = get_streams_traffic(stream_ids=traffic_stream_ids)
|
||||||
|
|
||||||
# The highly optimized bulk_get_subscriber_user_ids wants to know which
|
# The highly optimized bulk_get_subscriber_user_ids wants to know which
|
||||||
# streams we are subscribed to, for validation purposes, and it uses that
|
# streams we are subscribed to, for validation purposes, and it uses that
|
||||||
# info to know if it's allowed to find OTHER subscribers.
|
# info to know if it's allowed to find OTHER subscribers.
|
||||||
subscribed_stream_ids = {sub["stream_id"] for sub in sub_dicts if sub["active"]}
|
subscribed_stream_ids = {get_stream_id(sub) for sub in sub_dicts if sub["active"]}
|
||||||
|
|
||||||
if include_subscribers:
|
if include_subscribers:
|
||||||
subscriber_map: Mapping[int, Optional[List[int]]] = bulk_get_subscriber_user_ids(
|
subscriber_map: Mapping[int, Optional[List[int]]] = bulk_get_subscriber_user_ids(
|
||||||
@@ -5035,7 +5032,7 @@ def gather_subscriptions_helper(user_profile: UserProfile,
|
|||||||
|
|
||||||
sub_unsub_stream_ids = set()
|
sub_unsub_stream_ids = set()
|
||||||
for sub in sub_dicts:
|
for sub in sub_dicts:
|
||||||
stream_id = sub["stream_id"]
|
stream_id = get_stream_id(sub)
|
||||||
sub_unsub_stream_ids.add(stream_id)
|
sub_unsub_stream_ids.add(stream_id)
|
||||||
stream = all_streams_map[stream_id]
|
stream = all_streams_map[stream_id]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user