From 079d06dddffb8d98ff79b418617b48a3cb5db81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Fri, 23 Aug 2024 15:06:00 -0700 Subject: [PATCH] performance: Check if pubkey is registered before mutelist lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel D’Aquino --- src/notification_manager/notification_manager.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/notification_manager/notification_manager.rs b/src/notification_manager/notification_manager.rs index db93c12..739403d 100644 --- a/src/notification_manager/notification_manager.rs +++ b/src/notification_manager/notification_manager.rs @@ -207,13 +207,20 @@ impl NotificationManager { ) -> Result, Box> { let notification_status = self.get_notification_status(event).await?; let relevant_pubkeys = self.pubkeys_relevant_to_event(event).await?; + let mut relevant_pubkeys_that_are_registered = HashSet::new(); + for pubkey in relevant_pubkeys { + if self.is_pubkey_registered(&pubkey).await? { + relevant_pubkeys_that_are_registered.insert(pubkey); + } + } let pubkeys_that_received_notification = notification_status.pubkeys_that_received_notification(); - let relevant_pubkeys_yet_to_receive: HashSet = relevant_pubkeys + let relevant_pubkeys_yet_to_receive: HashSet = relevant_pubkeys_that_are_registered .difference(&pubkeys_that_received_notification) .filter(|&x| *x != event.pubkey) .cloned() .collect(); + let mut pubkeys_to_notify = HashSet::new(); for pubkey in relevant_pubkeys_yet_to_receive { @@ -298,6 +305,13 @@ impl NotificationManager { _ => Ok(false), } } + + async fn is_pubkey_registered( + &self, + pubkey: &PublicKey, + ) -> Result> { + Ok(!self.get_user_device_tokens(pubkey).await?.is_empty()) + } async fn get_user_device_tokens( &self,