Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
push_notification: Avoid extra DB call to fetch realm.
Prakhar Pratyushee9a0fdc9735
diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.pyindex 9cf02c459a0..c8d9c0582c4 100644--- a/zerver/lib/push_notifications.py+++ b/zerver/lib/push_notifications.py@@ -1780,7 +1780,7 @@ def handle_push_notification(user_profile_id: int, missed_message: dict[str, Any# the sender because they are sending a message to a public# stream that you are subscribed to but they are not.- can_access_sender = check_can_access_user(message.sender, user_profile)+ can_access_sender = check_can_access_user(message.sender, user_profile, message.realm)else:# For private messages, the recipient will gain access# to the sender if they did not had access previously.diff --git a/zerver/lib/users.py b/zerver/lib/users.pyindex 8d48eb135e6..55039c47d21 100644--- a/zerver/lib/users.py+++ b/zerver/lib/users.py@@ -686,11 +686,19 @@ def all_users_accessible_by_everyone_in_realm(realm: Realm) -> bool:return False-def user_access_restricted_in_realm(target_user: UserProfile) -> bool:+def user_access_restricted_in_realm(+ target_user: UserProfile,+ # Pass `realm` to avoid a DB query when `target_user.realm` isn't already+ # loaded but the caller has realm available from another source.+ realm: Realm | None = None,+) -> bool:if target_user.is_bot:return False- if all_users_accessible_by_everyone_in_realm(target_user.realm):+ if realm is None:+ realm = target_user.realm++ if all_users_accessible_by_everyone_in_realm(realm):return Falsereturn True@@ -717,9 +725,13 @@ def check_user_can_access_all_users(acting_user: UserProfile | None) -> bool:def check_can_access_user(- target_user: UserProfile, user_profile: UserProfile | None = None+ target_user: UserProfile,+ user_profile: UserProfile | None = None,+ # Pass `realm` to avoid a DB query when `target_user.realm` isn't already+ # loaded but the caller has realm available from another source.+ realm: Realm | None = None,) -> bool:- if not user_access_restricted_in_realm(target_user):+ if not user_access_restricted_in_realm(target_user, realm):return Trueif check_user_can_access_all_users(user_profile):