mirror of
https://github.com/nostrlabs-io/notepush.git
synced 2025-06-15 11:28:23 +00:00
performance: Check if pubkey is registered before mutelist lookup
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
@ -207,13 +207,20 @@ impl NotificationManager {
|
|||||||
) -> Result<HashSet<nostr::PublicKey>, Box<dyn std::error::Error>> {
|
) -> Result<HashSet<nostr::PublicKey>, Box<dyn std::error::Error>> {
|
||||||
let notification_status = self.get_notification_status(event).await?;
|
let notification_status = self.get_notification_status(event).await?;
|
||||||
let relevant_pubkeys = self.pubkeys_relevant_to_event(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 =
|
let pubkeys_that_received_notification =
|
||||||
notification_status.pubkeys_that_received_notification();
|
notification_status.pubkeys_that_received_notification();
|
||||||
let relevant_pubkeys_yet_to_receive: HashSet<PublicKey> = relevant_pubkeys
|
let relevant_pubkeys_yet_to_receive: HashSet<PublicKey> = relevant_pubkeys_that_are_registered
|
||||||
.difference(&pubkeys_that_received_notification)
|
.difference(&pubkeys_that_received_notification)
|
||||||
.filter(|&x| *x != event.pubkey)
|
.filter(|&x| *x != event.pubkey)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
||||||
let mut pubkeys_to_notify = HashSet::new();
|
let mut pubkeys_to_notify = HashSet::new();
|
||||||
for pubkey in relevant_pubkeys_yet_to_receive {
|
for pubkey in relevant_pubkeys_yet_to_receive {
|
||||||
@ -298,6 +305,13 @@ impl NotificationManager {
|
|||||||
_ => Ok(false),
|
_ => Ok(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn is_pubkey_registered(
|
||||||
|
&self,
|
||||||
|
pubkey: &PublicKey,
|
||||||
|
) -> Result<bool, Box<dyn std::error::Error>> {
|
||||||
|
Ok(!self.get_user_device_tokens(pubkey).await?.is_empty())
|
||||||
|
}
|
||||||
|
|
||||||
async fn get_user_device_tokens(
|
async fn get_user_device_tokens(
|
||||||
&self,
|
&self,
|
||||||
|
Reference in New Issue
Block a user