Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
cache: Use `id`s instead of `UserProfile`s for get_muting_users.
Abhijeet Prasad Bodasb7fcb0275c1c
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex 71ee4828749..68e43cd62ab 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -1862,7 +1862,7 @@ def do_send_messages(mentioned_user_ids = send_request.message.mentions_user_ids# Extend the set with users who have muted the sender.- mark_as_read_for_users = get_muting_users(send_request.message.sender)+ mark_as_read_for_users = get_muting_users(send_request.message.sender_id)mark_as_read_for_users.update(mark_as_read)user_messages = create_user_messages(diff --git a/zerver/lib/cache.py b/zerver/lib/cache.pyindex 35334543de6..330d19fb0cd 100644--- a/zerver/lib/cache.py+++ b/zerver/lib/cache.py@@ -535,8 +535,8 @@ def realm_user_dicts_cache_key(realm_id: int) -> str:return f"realm_user_dicts:{realm_id}"-def get_muting_users_cache_key(muted_user: "UserProfile") -> str:- return f"muting_users_list:{muted_user.id}"+def get_muting_users_cache_key(muted_user_id: int) -> str:+ return f"muting_users_list:{muted_user_id}"def get_realm_used_upload_space_cache_key(realm: "Realm") -> str:@@ -649,7 +649,7 @@ def flush_user_profile(sender: Any, **kwargs: Any) -> None:def flush_muting_users_cache(sender: Any, **kwargs: Any) -> None:mute_object = kwargs["instance"]- cache_delete(get_muting_users_cache_key(mute_object.muted_user))+ cache_delete(get_muting_users_cache_key(mute_object.muted_user_id))# Called by models.py to flush various caches whenever we savediff --git a/zerver/lib/user_mutes.py b/zerver/lib/user_mutes.pyindex bb95d875c5c..71389db7041 100644--- a/zerver/lib/user_mutes.py+++ b/zerver/lib/user_mutes.py@@ -38,7 +38,7 @@ def get_mute_object(user_profile: UserProfile, muted_user: UserProfile) -> Optio@cache_with_key(get_muting_users_cache_key, timeout=3600 * 24 * 7)-def get_muting_users(muted_user: UserProfile) -> Set[int]:+def get_muting_users(muted_user_id: int) -> Set[int]:"""This is kind of the inverse of `get_user_mutes` above.While `get_user_mutes` is mainly used for event system work,@@ -47,6 +47,6 @@ def get_muting_users(muted_user: UserProfile) -> Set[int]:The result will also include deactivated users."""rows = MutedUser.objects.filter(- muted_user=muted_user,+ muted_user_id=muted_user_id,).values("user_profile_id")return {row["user_profile_id"] for row in rows}diff --git a/zerver/tests/test_muting_users.py b/zerver/tests/test_muting_users.pyindex 81ff6ae390d..ff1fc77a5ba 100644--- a/zerver/tests/test_muting_users.py+++ b/zerver/tests/test_muting_users.py@@ -168,23 +168,23 @@ class MutedUsersTests(ZulipTestCase):self.login_user(hamlet)cordelia = self.example_user("cordelia")- self.assertEqual(None, cache_get(get_muting_users_cache_key(cordelia)))- self.assertEqual(set(), get_muting_users(cordelia))- self.assertEqual(set(), cache_get(get_muting_users_cache_key(cordelia))[0])+ self.assertEqual(None, cache_get(get_muting_users_cache_key(cordelia.id)))+ self.assertEqual(set(), get_muting_users(cordelia.id))+ self.assertEqual(set(), cache_get(get_muting_users_cache_key(cordelia.id))[0])url = "/api/v1/users/me/muted_users/{}".format(cordelia.id)result = self.api_post(hamlet, url)self.assert_json_success(result)- self.assertEqual(None, cache_get(get_muting_users_cache_key(cordelia)))- self.assertEqual({hamlet.id}, get_muting_users(cordelia))- self.assertEqual({hamlet.id}, cache_get(get_muting_users_cache_key(cordelia))[0])+ self.assertEqual(None, cache_get(get_muting_users_cache_key(cordelia.id)))+ self.assertEqual({hamlet.id}, get_muting_users(cordelia.id))+ self.assertEqual({hamlet.id}, cache_get(get_muting_users_cache_key(cordelia.id))[0])url = "/api/v1/users/me/muted_users/{}".format(cordelia.id)result = self.api_delete(hamlet, url)self.assert_json_success(result)- self.assertEqual(None, cache_get(get_muting_users_cache_key(cordelia)))- self.assertEqual(set(), get_muting_users(cordelia))- self.assertEqual(set(), cache_get(get_muting_users_cache_key(cordelia))[0])+ self.assertEqual(None, cache_get(get_muting_users_cache_key(cordelia.id)))+ self.assertEqual(set(), get_muting_users(cordelia.id))+ self.assertEqual(set(), cache_get(get_muting_users_cache_key(cordelia.id))[0])def assert_usermessage_read_flag(self, user: UserProfile, message: int, flag: bool) -> None:usermesaage = UserMessage.objects.get(