Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
streams: Compute object only when needed.
Sahil Batrab20c24c09d17
diff --git a/zerver/actions/streams.py b/zerver/actions/streams.pyindex 725bced6c7d..6d0d15de093 100644--- a/zerver/actions/streams.py+++ b/zerver/actions/streams.py@@ -466,7 +466,7 @@ def send_stream_creation_events_for_previously_inaccessible_streams(for setting_name in Stream.stream_permission_group_settings:setting_group_ids.add(getattr(stream, setting_name + "_id"))- setting_groups_dict = get_setting_values_for_group_settings(list(setting_group_ids))+ setting_groups_dict: dict[int, int | AnonymousSettingGroupDict] | None = Nonefor stream_id, stream_users_ids in altered_user_dict.items():stream = stream_dict[stream_id]@@ -488,6 +488,9 @@ def send_stream_creation_events_for_previously_inaccessible_streams(notify_user_ids = list(stream_users_ids & altered_guests)if notify_user_ids:+ if setting_groups_dict is None:+ setting_groups_dict = get_setting_values_for_group_settings(list(setting_group_ids))+send_stream_creation_event(realm, stream, notify_user_ids, recent_traffic, setting_groups_dict)diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex 176b5e2eeb4..a61de9f0174 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -4801,7 +4801,7 @@ class SubscriptionAPITest(ZulipTestCase):streams_to_sub = ["multi_user_stream"]with (self.capture_send_event_calls(expected_num_events=5) as events,- self.assert_database_query_count(40),+ self.assert_database_query_count(39),):self.common_subscribe_to_streams(self.test_user,@@ -4827,7 +4827,7 @@ class SubscriptionAPITest(ZulipTestCase):# Now add ourselveswith (self.capture_send_event_calls(expected_num_events=2) as events,- self.assert_database_query_count(16),+ self.assert_database_query_count(15),):self.common_subscribe_to_streams(self.test_user,@@ -5273,7 +5273,7 @@ class SubscriptionAPITest(ZulipTestCase):test_user_ids = [user.id for user in test_users]with (- self.assert_database_query_count(18),+ self.assert_database_query_count(17),self.assert_memcached_count(3),mock.patch("zerver.views.streams.send_messages_for_new_subscribers"),):@@ -5641,7 +5641,7 @@ class SubscriptionAPITest(ZulipTestCase):]# Test creating a public stream when realm does not have a notification stream.- with self.assert_database_query_count(40):+ with self.assert_database_query_count(39):self.common_subscribe_to_streams(self.test_user,[new_streams[0]],@@ -5661,7 +5661,7 @@ class SubscriptionAPITest(ZulipTestCase):new_stream_announcements_stream = get_stream(self.streams[0], self.test_realm)self.test_realm.new_stream_announcements_stream_id = new_stream_announcements_stream.idself.test_realm.save()- with self.assert_database_query_count(51):+ with self.assert_database_query_count(50):self.common_subscribe_to_streams(self.test_user,[new_streams[2]],