mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-01-03 16:34:20 +01:00
since filter optimization
This is an optimization that allows us to modify our network filter to include since-information based off of our local relay. The idea is to look at the latest note in a given view, and add that to the since filter for the remote query. Fixes: https://github.com/damus-io/notedeck/issues/36 Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
20
src/app.rs
20
src/app.rs
@@ -70,6 +70,20 @@ fn relay_setup(pool: &mut RelayPool, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
|
||||
fn since_optimize_filter(filter: &mut enostr::Filter, notes: &[NoteRef]) {
|
||||
// Get the latest entry in the events
|
||||
if notes.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
// get the latest note
|
||||
let latest = notes[0];
|
||||
let since = latest.created_at - 60;
|
||||
|
||||
// update the filters
|
||||
filter.since = Some(since);
|
||||
}
|
||||
|
||||
fn send_initial_filters(damus: &mut Damus, relay_url: &str) {
|
||||
info!("Sending initial filters to {}", relay_url);
|
||||
let mut c: u32 = 1;
|
||||
@@ -78,7 +92,11 @@ fn send_initial_filters(damus: &mut Damus, relay_url: &str) {
|
||||
let relay = &mut relay.relay;
|
||||
if relay.url == relay_url {
|
||||
for timeline in &damus.timelines {
|
||||
relay.subscribe(format!("initial{}", c), timeline.filter.clone());
|
||||
let mut filter = timeline.filter.clone();
|
||||
for f in &mut filter {
|
||||
since_optimize_filter(f, &timeline.notes);
|
||||
}
|
||||
relay.subscribe(format!("initial{}", c), filter);
|
||||
c += 1;
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user