make since optimize accept Option<&NoteRef> instead of notes
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -183,21 +183,24 @@ pub fn should_since_optimize(limit: u64, num_notes: usize) -> bool {
|
||||
limit as usize <= num_notes
|
||||
}
|
||||
|
||||
pub fn since_optimize_filter_with(filter: Filter, notes: &[NoteRef], since_gap: u64) -> Filter {
|
||||
pub fn since_optimize_filter_with(
|
||||
filter: Filter,
|
||||
latest_note: Option<&NoteRef>,
|
||||
since_gap: u64,
|
||||
) -> Filter {
|
||||
// Get the latest entry in the events
|
||||
if notes.is_empty() {
|
||||
let Some(latest) = latest_note else {
|
||||
return filter;
|
||||
}
|
||||
};
|
||||
|
||||
// get the latest note
|
||||
let latest = notes[0];
|
||||
let since = latest.created_at - since_gap;
|
||||
|
||||
filter.since_mut(since)
|
||||
}
|
||||
|
||||
pub fn since_optimize_filter(filter: Filter, notes: &[NoteRef]) -> Filter {
|
||||
since_optimize_filter_with(filter, notes, 60)
|
||||
pub fn since_optimize_filter(filter: Filter, latest: Option<&NoteRef>) -> Filter {
|
||||
since_optimize_filter_with(filter, latest, 60)
|
||||
}
|
||||
|
||||
pub fn default_limit() -> u64 {
|
||||
|
||||
@@ -552,7 +552,7 @@ pub fn send_initial_timeline_filter(
|
||||
// notes than the limit, we might want to backfill
|
||||
// older notes
|
||||
if can_since_optimize && filter::should_since_optimize(lim, notes.len()) {
|
||||
filter = filter::since_optimize_filter(filter, notes);
|
||||
filter = filter::since_optimize_filter(filter, Some(¬es[0]));
|
||||
} else {
|
||||
warn!("Skipping since optimization for {:?}: number of local notes is less than limit, attempting to backfill.", &timeline.kind);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user