Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

since filter optimization #39

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions enostr/src/relay/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use ewebsock::{WsMessage, WsReceiver, WsSender};

use crate::{ClientMessage, Filter, Result};
use log::info;
use std::fmt;
use std::hash::{Hash, Hasher};

Expand Down Expand Up @@ -77,6 +78,10 @@ impl Relay {
}

pub fn subscribe(&mut self, subid: String, filters: Vec<Filter>) {
info!(
"sending '{}' subscription to relay pool: {:?}",
subid, filters
);
self.send(&ClientMessage::req(subid, filters));
}
}
2 changes: 1 addition & 1 deletion queries/global.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"limit": 10, "kinds":[1]}]
[{"limit": 100, "kinds":[1]}]
2 changes: 1 addition & 1 deletion queries/notifications.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"limit": 1000, "kinds":[1], "#p": ["32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"]}]
[{"limit": 100, "kinds":[1], "#p": ["32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"]}]
20 changes: 19 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ pub fn padding<R>(
.show(ui, add_contents)
}

pub fn is_mobile(ctx: &egui::Context) -> bool {
//true
let screen_size = ctx.screen_rect().size();
screen_size.x < 550.0
#[inline]
pub fn is_mobile(_ctx: &egui::Context) -> bool {
#[cfg(any(target_os = "android", target_os = "ios"))]
{
true
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
{
false
}
}
50 changes: 27 additions & 23 deletions src/ui/note/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod options;
pub use contents::NoteContents;
pub use options::NoteOptions;

use crate::{colors, ui, Damus};
use crate::{colors, ui, ui::is_mobile, Damus};
use egui::{Label, RichText, Sense};
use nostrdb::{NoteKey, Transaction};
use std::hash::{Hash, Hasher};
Expand Down Expand Up @@ -207,28 +207,32 @@ impl<'a> Note<'a> {
let profile_key = profile.as_ref().unwrap().record().note_key();
let note_key = note_key.as_u64();

let (rect, size) = ui::anim::hover_expand(
ui,
egui::Id::new(ProfileAnimId {
profile_key,
note_key,
}),
ui::ProfilePic::default_size(),
expand_size,
anim_speed,
);

ui.put(
rect,
ui::ProfilePic::new(&mut self.app.img_cache, pic).size(size),
)
.on_hover_ui_at_pointer(|ui| {
ui.set_max_width(300.0);
ui.add(ui::ProfilePreview::new(
profile.as_ref().unwrap(),
&mut self.app.img_cache,
));
});
if is_mobile(ui.ctx()) {
ui.add(ui::ProfilePic::new(&mut self.app.img_cache, pic));
} else {
let (rect, size) = ui::anim::hover_expand(
ui,
egui::Id::new(ProfileAnimId {
profile_key,
note_key,
}),
ui::ProfilePic::default_size(),
expand_size,
anim_speed,
);

ui.put(
rect,
ui::ProfilePic::new(&mut self.app.img_cache, pic).size(size),
)
.on_hover_ui_at_pointer(|ui| {
ui.set_max_width(300.0);
ui.add(ui::ProfilePreview::new(
profile.as_ref().unwrap(),
&mut self.app.img_cache,
));
});
}
}
None => {
ui.add(ui::ProfilePic::new(
Expand Down
2 changes: 1 addition & 1 deletion src/ui/profile/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'cache, 'url> ProfilePic<'cache, 'url> {
}

pub fn default_size() -> f32 {
32.0
38.0
}

pub fn no_pfp_url() -> &'static str {
Expand Down
Loading