mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-02-18 06:54:20 +01:00
feat(reactions): use ProfileKey when possible for performance
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -370,6 +370,7 @@ mod tests {
|
||||
reaction: Reaction {
|
||||
reaction: "+".to_owned(),
|
||||
sender: self.random_sender(),
|
||||
sender_profilekey: None,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user