Skip to content

Commit

Permalink
Skip too frequent segment headers sync requests
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Jun 24, 2024
1 parent 4914476 commit 3f9bc0b
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ use tokio::sync::watch;
use tokio_stream::wrappers::WatchStream;
use tracing::{info, trace, warn};

const SEGMENT_HEADERS_SYNC_INTERVAL: Duration = Duration::from_secs(1);
const FARMER_APP_INFO_DEDUPLICATION_WINDOW: Duration = Duration::from_secs(1);

#[derive(Debug, Default)]
struct SegmentHeaders {
segment_headers: Vec<SegmentHeader>,
last_synced: Option<Instant>,
}

impl SegmentHeaders {
Expand Down Expand Up @@ -59,6 +61,13 @@ impl SegmentHeaders {
where
NC: NodeClient,
{
if let Some(last_synced) = &self.last_synced {
if last_synced.elapsed() < SEGMENT_HEADERS_SYNC_INTERVAL {
return Ok(());
}
}
self.last_synced.replace(Instant::now());

let mut segment_index_offset = SegmentIndex::from(self.segment_headers.len() as u64);
let segment_index_step = SegmentIndex::from(MAX_SEGMENT_HEADERS_PER_REQUEST as u64);

Expand Down

0 comments on commit 3f9bc0b

Please sign in to comment.