Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
register: Optmize computing can_invite_others_to_realm.
Sahil Batra0d5d305a47c4
diff --git a/zerver/lib/events.py b/zerver/lib/events.pyindex 29b19785fe3..253e1b359e5 100644--- a/zerver/lib/events.py+++ b/zerver/lib/events.py@@ -589,7 +589,9 @@ def fetch_initial_state_data(or state["can_create_web_public_streams"])state["can_subscribe_other_users"] = settings_user.can_subscribe_other_users()- state["can_invite_others_to_realm"] = settings_user.can_invite_users_by_email(realm)+ state["can_invite_others_to_realm"] = (+ realm.can_invite_users_group_id in settings_user_recursive_group_ids+ )state["is_admin"] = settings_user.is_realm_adminstate["is_owner"] = settings_user.is_realm_ownerstate["is_moderator"] = settings_user.is_moderatordiff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.pyindex f6ee63489c1..4346bff2402 100644--- a/zerver/tests/test_event_system.py+++ b/zerver/tests/test_event_system.py@@ -1193,7 +1193,7 @@ class FetchQueriesTest(ZulipTestCase):realm = get_realm_with_settings(realm_id=user.realm_id)with (- self.assert_database_query_count(43),+ self.assert_database_query_count(42),mock.patch("zerver.lib.events.always_want") as want_mock,):fetch_initial_state_data(user, realm=realm)@@ -1218,7 +1218,7 @@ class FetchQueriesTest(ZulipTestCase):realm_filters=0,realm_linkifiers=0,realm_playgrounds=1,- realm_user=5,+ realm_user=4,realm_user_groups=3,realm_user_settings_defaults=1,recent_private_conversations=1,diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.pyindex 1bcc4628e78..c4371f76549 100644--- a/zerver/tests/test_home.py+++ b/zerver/tests/test_home.py@@ -271,7 +271,7 @@ class HomeTest(ZulipTestCase):# Verify succeeds once logged-inwith (- self.assert_database_query_count(53),+ self.assert_database_query_count(52),patch("zerver.lib.cache.cache_set") as cache_mock,):result = self._get_home_page(stream="Denmark")@@ -576,7 +576,7 @@ class HomeTest(ZulipTestCase):# Verify number of queries for Realm admin isn't much higher than for normal users.self.login("iago")with (- self.assert_database_query_count(53),+ self.assert_database_query_count(52),patch("zerver.lib.cache.cache_set") as cache_mock,):result = self._get_home_page()@@ -608,7 +608,7 @@ class HomeTest(ZulipTestCase):self._get_home_page()# Then for the second page load, measure the number of queries.- with self.assert_database_query_count(48):+ with self.assert_database_query_count(47):result = self._get_home_page()# Do a sanity check that our new streams were in the payload.