From 41eb6d947c03e214e3989c733c1099423524385f Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 4 Jan 2024 17:57:24 -0800 Subject: [PATCH] zilencer: Clean up realms return structure. It seems most correct to answer the question about whether push notifications are working specifically for the exact set of realms that the server self-reported to us in fact exist. Sending data on any additional realms that were not referenced in the request (if that's somehow possible without them being locally deleted) is likely to only be confusing. And the client should reasonably be able to expect to get a response covering exactly the realms it told us about. --- zilencer/views.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/zilencer/views.py b/zilencer/views.py index ac681721ea..c045568e9c 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -1092,10 +1092,16 @@ def remote_server_post_analytics( assert log_data is not None can_push_values = set() - remote_realms = RemoteRealm.objects.filter(server=server, realm_locally_deleted=False) + # Return details on exactly the set of remote realm the client told us about. remote_realm_dict: Dict[str, RemoteRealmDictValue] = {} - remote_human_realm_count = remote_realms.filter(is_system_bot_realm=False).count() - for remote_realm in remote_realms: + remote_human_realm_count = len( + [ + remote_realm + for remote_realm in realm_id_to_remote_realm.values() + if not remote_realm.is_system_bot_realm + ] + ) + for remote_realm in realm_id_to_remote_realm.values(): uuid = str(remote_realm.uuid) status = get_push_status_for_remote_request(server, remote_realm) if remote_realm.is_system_bot_realm: @@ -1122,7 +1128,7 @@ def remote_server_post_analytics( def build_realm_id_to_remote_realm_dict( server: RemoteZulipServer, realms: Optional[List[RealmDataForAnalytics]] -) -> Dict[int, Optional[RemoteRealm]]: +) -> Dict[int, RemoteRealm]: if realms is None: return {}