mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 16:31:18 +00:00
Reapply feed calculation optimizations
This commit is contained in:
parent
0a83f8bcdc
commit
940f581080
52
src/feed.rs
52
src/feed.rs
@ -228,42 +228,33 @@ impl Feed {
|
|||||||
}
|
}
|
||||||
FeedKind::Inbox(with_replies) => {
|
FeedKind::Inbox(with_replies) => {
|
||||||
if let Some(my_pubkey) = GLOBALS.signer.public_key() {
|
if let Some(my_pubkey) = GLOBALS.signer.public_key() {
|
||||||
let events: Vec<Event> = GLOBALS
|
let my_event_ids: HashSet<Id> = GLOBALS
|
||||||
.events
|
.events
|
||||||
.iter()
|
|
||||||
.map(|r| r.value().to_owned())
|
|
||||||
.filter(|e| e.created_at <= now) // no future events
|
|
||||||
.filter(|e| {
|
|
||||||
// feed related
|
|
||||||
e.kind == EventKind::TextNote
|
|
||||||
|| e.kind == EventKind::EncryptedDirectMessage
|
|
||||||
|| (settings.reposts && (e.kind == EventKind::Repost))
|
|
||||||
})
|
|
||||||
.filter(|e| !dismissed.contains(&e.id)) // not dismissed
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let my_event_ids: HashSet<Id> = events
|
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|e| {
|
.filter_map(|e| {
|
||||||
if e.pubkey == my_pubkey {
|
if e.value().pubkey == my_pubkey {
|
||||||
Some(e.id)
|
Some(e.value().id)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut inbox_events: Vec<(Unixtime, Id)> = events
|
let mut inbox_events: Vec<(Unixtime, Id)> = GLOBALS
|
||||||
|
.events
|
||||||
.iter()
|
.iter()
|
||||||
|
.filter(|e| e.value().created_at <= now) // no future events
|
||||||
|
.filter(|e| {
|
||||||
|
// feed related
|
||||||
|
e.value().kind == EventKind::TextNote
|
||||||
|
|| e.value().kind == EventKind::EncryptedDirectMessage
|
||||||
|
|| (settings.reposts && (e.value().kind == EventKind::Repost))
|
||||||
|
})
|
||||||
|
.filter(|e| !dismissed.contains(&e.value().id)) // not dismissed
|
||||||
|
.filter(|e| e.value().pubkey != my_pubkey) // not self-authored
|
||||||
.filter(|e| {
|
.filter(|e| {
|
||||||
// Don't include my own posts
|
|
||||||
if e.pubkey == my_pubkey {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Include if it directly replies to one of my events
|
// Include if it directly replies to one of my events
|
||||||
// FIXME: maybe try replies_to_ancestors to go deeper
|
if let Some((id, _)) = e.value().replies_to() {
|
||||||
if let Some((id, _)) = e.replies_to() {
|
|
||||||
if my_event_ids.contains(&id) {
|
if my_event_ids.contains(&id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -271,11 +262,11 @@ impl Feed {
|
|||||||
|
|
||||||
if with_replies {
|
if with_replies {
|
||||||
// Include if it tags me
|
// Include if it tags me
|
||||||
e.people().iter().any(|(p, _, _)| *p == my_pubkey.into())
|
e.value().people().iter().any(|(p, _, _)| *p == my_pubkey.into())
|
||||||
} else {
|
} else {
|
||||||
if e.kind != EventKind::EncryptedDirectMessage {
|
if e.value().kind != EventKind::EncryptedDirectMessage {
|
||||||
// Include if it directly references me in the content
|
// Include if it directly references me in the content
|
||||||
e.referenced_people()
|
e.value().referenced_people()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|(p, _, _)| *p == my_pubkey.into())
|
.any(|(p, _, _)| *p == my_pubkey.into())
|
||||||
} else {
|
} else {
|
||||||
@ -283,9 +274,12 @@ impl Feed {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map(|e| (e.created_at, e.id))
|
.map(|e| (e.value().created_at, e.value().id))
|
||||||
.collect();
|
.collect();
|
||||||
inbox_events.sort_by(|a, b| b.0.cmp(&a.0));
|
|
||||||
|
// Sort
|
||||||
|
inbox_events.sort_unstable_by(|a, b| b.0.cmp(&a.0));
|
||||||
|
|
||||||
*self.inbox_feed.write() = inbox_events.iter().map(|e| e.1).collect();
|
*self.inbox_feed.write() = inbox_events.iter().map(|e| e.1).collect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user