perf: Make max gap depth fetch configurable

This commit is contained in:
timedout
2026-05-26 20:11:53 +01:00
parent b925936195
commit d15064871e
@@ -100,10 +100,10 @@ impl super::Service {
/// filled the gap, i.e. when the remote says there's no more events. /// filled the gap, i.e. when the remote says there's no more events.
/// ///
/// This function will iterate until the remote returns no more events, /// This function will iterate until the remote returns no more events,
/// increasing the limit by a factor of 10. If 20 iterations are reached or /// increasing the limit by a factor of 10. If 100 iterations are reached or
/// 200 events are backfilled, the function will give up and return what it /// max_fetch_prev_events events are backfilled, the function will give up
/// has, to avoid pulling in too much data (for example, absurdly large /// and return what it has, to avoid pulling in too much data (for example,
/// gaps). /// absurdly large gaps).
/// ///
/// This function does not persist the events. The caller is responsible for /// This function does not persist the events. The caller is responsible for
/// passing them through handle_incoming_pdu. /// passing them through handle_incoming_pdu.
@@ -154,7 +154,7 @@ impl super::Service {
let mut iterations = 0_u8; let mut iterations = 0_u8;
loop { loop {
iterations = iterations.saturating_add(1); iterations = iterations.saturating_add(1);
let limit = iterations.saturating_mul(10); let limit = iterations.saturating_mul(10).min(100);
debug_info!(%limit, %via, %iterations, "Attempting to gap fill missing events"); debug_info!(%limit, %via, %iterations, "Attempting to gap fill missing events");
let response: get_missing_events::v1::Response = self let response: get_missing_events::v1::Response = self
.services .services
@@ -206,8 +206,15 @@ impl super::Service {
if latest_events.is_empty() { if latest_events.is_empty() {
break; break;
} else if discovered.len() >= 200 || iterations >= 20 { } else if discovered.len() > self.services.server.config.max_fetch_prev_events.into()
error!("Gap too large, giving up"); || iterations >= 20
{
error!(
filled=discovered.len(),
max_fetch_prev_events=self.services.server.config.max_fetch_prev_events,
%iterations,
"Gap too large, giving up"
);
break; break;
} }
} }