perf: improve filter generation performance

for some reason the filter here was taking ~6ms to create...

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-09-30 18:05:12 -04:00
parent 810b4c1990
commit af53dd4852
2 changed files with 11 additions and 3 deletions

View File

@@ -626,11 +626,15 @@ impl TimelineKind {
pub fn notifications_filter(pk: &Pubkey) -> Filter { pub fn notifications_filter(pk: &Pubkey) -> Filter {
Filter::new() Filter::new()
.pubkeys([pk.bytes()]) .pubkeys([pk.bytes()])
.kinds([1, 7, 6]) .kinds(notification_kinds())
.limit(default_limit()) .limit(default_limit())
.build() .build()
} }
pub fn notification_kinds() -> [u64; 3] {
[1, 7, 6]
}
#[derive(Debug)] #[derive(Debug)]
pub struct TitleNeedsDb<'a> { pub struct TitleNeedsDb<'a> {
kind: &'a TimelineKind, kind: &'a TimelineKind,

View File

@@ -25,8 +25,12 @@ pub fn unseen_notification(
profiling::scope!("NotesFreshness::update closure"); profiling::scope!("NotesFreshness::update closure");
let filter = { let filter = {
profiling::scope!("NotesFreshness::update filter instantiation"); profiling::scope!("NotesFreshness::update filter instantiation");
crate::timeline::kind::notifications_filter(&current_pk) enostr::Filter::new_with_capacity(1)
.since_mut(timestamp_last_viewed) .pubkeys([current_pk.bytes()])
.kinds(crate::timeline::kind::notification_kinds())
.limit(1)
.since(timestamp_last_viewed)
.build()
}; };
let txn = Transaction::new(ndb).expect("txn"); let txn = Transaction::new(ndb).expect("txn");