feat(reactions): use ProfileKey when possible for performance

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-10-24 10:58:48 -04:00
parent 892d77d4e3
commit fdde0244e2
4 changed files with 19 additions and 7 deletions

View File

@@ -370,6 +370,7 @@ mod tests {
reaction: Reaction {
reaction: "+".to_owned(),
sender: self.random_sender(),
sender_profilekey: None,
},
}))
}

View File

@@ -169,6 +169,11 @@ fn to_reaction<'a>(
created_at: reacted_to_note.created_at(),
};
let sender_profilekey = ndb
.get_profile_by_pubkey(txn, payload.note.pubkey())
.ok()
.and_then(|p| p.key());
Some(ReactionResponse {
fragment: ReactionFragment {
noteref_reacted_to,
@@ -176,6 +181,7 @@ fn to_reaction<'a>(
reaction: Reaction {
reaction: reaction.to_string(),
sender: Pubkey::new(*payload.note.pubkey()),
sender_profilekey,
},
},
pk: payload.note.pubkey(),

View File

@@ -1,6 +1,7 @@
use std::collections::{BTreeMap, HashSet};
use enostr::Pubkey;
use nostrdb::ProfileKey;
use notedeck::NoteRef;
use crate::timeline::note_units::{CompositeKey, CompositeType, UnitKey};
@@ -275,6 +276,7 @@ impl ReactionFragment {
pub struct Reaction {
pub reaction: String, // can't use char because some emojis are 'grapheme clusters'
pub sender: Pubkey,
pub sender_profilekey: Option<ProfileKey>,
}
/// Represents a singular repost

View File

@@ -711,13 +711,16 @@ fn render_reaction_cluster(
.reactions
.values()
.filter(|r| !mute.is_pk_muted(r.sender.bytes()))
.map(|r| &r.sender)
.map(|p| {
profiling::scope!("ndb by pubkey");
ProfileEntry {
record: note_context.ndb.get_profile_by_pubkey(txn, p.bytes()).ok(),
pk: p,
}
.map(|r| (&r.sender, r.sender_profilekey))
.map(|(p, key)| {
let record = if let Some(key) = key {
profiling::scope!("ndb by key");
note_context.ndb.get_profile_by_key(txn, key).ok()
} else {
profiling::scope!("ndb by pubkey");
note_context.ndb.get_profile_by_pubkey(txn, p.bytes()).ok()
};
ProfileEntry { record, pk: p }
})
.collect()
};