commit d9f1582ee7ff7ac30c0ddd20e350cc20f34be8bc
parent f4d496012be57e68264a88e3d60265f6d50d1d37
Author: William Casarin <jb55@jb55.com>
Date: Thu, 18 Apr 2024 08:38:52 -0700
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>
Diffstat:
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/app.rs b/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;