Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

events: Optimize creating streams for new users.

Tim Abbott6d7cd351a361
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index 6df2887e0c0..acd84ce4dd5 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -441,7 +441,8 @@ def process_new_human_user(user_profile: UserProfile,
if stream not in streams:
streams.append(stream)
- bulk_add_subscriptions(realm, streams, [user_profile], acting_user=acting_user)
+ bulk_add_subscriptions(realm, streams, [user_profile], acting_user=acting_user,
+ from_user_creation=True)
add_new_user_history(user_profile, streams)
@@ -2779,7 +2780,8 @@ def bulk_add_subscriptions(
streams: Iterable[Stream],
users: Iterable[UserProfile],
color_map: Mapping[str, str]={},
- acting_user: Optional[UserProfile]=None
+ acting_user: Optional[UserProfile]=None,
+ from_user_creation: bool=False,
) -> SubT:
users = list(users)
@@ -2861,19 +2863,21 @@ def bulk_add_subscriptions(
)
# We now send several types of events to notify browsers. The
- # first batch is notifications to users on invite-only streams
- # that the stream exists.
- send_stream_creation_events_for_private_streams(
- realm=realm,
- stream_dict=stream_dict,
- altered_user_dict=altered_user_dict,
- )
+ # first batches of notifications are sent only to the user(s)
+ # being subscribed; we can skip these notifications when this is
+ # being called from the new user creation flow.
+ if not from_user_creation:
+ send_stream_creation_events_for_private_streams(
+ realm=realm,
+ stream_dict=stream_dict,
+ altered_user_dict=altered_user_dict,
+ )
- send_subscription_add_events(
- realm=realm,
- sub_info_list=subs_to_add + subs_to_activate,
- subscriber_dict=subscriber_peer_info.subscribed_ids,
- )
+ send_subscription_add_events(
+ realm=realm,
+ sub_info_list=subs_to_add + subs_to_activate,
+ subscriber_dict=subscriber_peer_info.subscribed_ids,
+ )
send_peer_subscriber_events(
op="peer_add",
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py
index 54f74371f8f..4483a5e17ef 100644
--- a/zerver/tests/test_signup.py
+++ b/zerver/tests/test_signup.py
@@ -649,7 +649,7 @@ class LoginTest(ZulipTestCase):
with queries_captured() as queries:
self.register(self.nonreg_email('test'), "test")
# Ensure the number of queries we make is not O(streams)
- self.assertEqual(len(queries), 75)
+ self.assertEqual(len(queries), 74)
user_profile = self.nonreg_user('test')
self.assert_logged_in_user_id(user_profile.id)
self.assertFalse(user_profile.enable_stream_desktop_notifications)
diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py
index 3f8473c10c7..45bec70c5c5 100644
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -769,9 +769,9 @@ class QueryCountTest(ZulipTestCase):
prereg_user=prereg_user,
)
- self.assert_length(queries, 81)
+ self.assert_length(queries, 76)
self.assert_length(cache_tries, 23)
- self.assert_length(events, 10)
+ self.assert_length(events, 7)
peer_add_events = [event for event in events if event["event"].get("op") == "peer_add"]