···177177 let from = params.to.map(Bound::Included).unwrap_or(Bound::Unbounded);
178178 let to = params.from.map(Bound::Included).unwrap_or(Bound::Unbounded);
179179 let maybe_hits = db
180180- .get_hits(¶ms.nsid, HitsRange { from, to })
180180+ .get_hits(¶ms.nsid, HitsRange { from, to }, MAX_HITS)
181181 .take(MAX_HITS);
182182 let mut hits = Vec::with_capacity(maybe_hits.size_hint().0);
183183
+7-3
server/src/db/mod.rs
···383383 &self,
384384 nsid: &str,
385385 range: impl RangeBounds<u64> + std::fmt::Debug,
386386+ max_items: usize,
386387 ) -> impl Iterator<Item = AppResult<handle::Item>> {
387388 let start_limit = match range.start_bound().cloned() {
388389 Bound::Included(start) => start,
···401402 };
402403403404 // let mut ts = CLOCK.now();
405405+ let mut current_item_count = 0;
404406 let map_block = move |(key, val)| {
405407 let mut key_reader = Cursor::new(key);
406408 let start_timestamp = key_reader.read_varint::<u64>()?;
407409 // let end_timestamp = key_reader.read_varint::<u64>()?;
408410 if start_timestamp < start_limit {
409411 // tracing::info!(
410410- // "skipped block with timestamps {start_timestamp}..{end_timestamp} because {start_limit} is greater"
412412+ // "stopped at block with timestamps {start_timestamp}..{end_timestamp} because {start_limit} is greater"
411413 // );
412414 return Ok(None);
413413- } else {
414414- // tracing::info!("using block with timestamp {start_timestamp}..{end_timestamp}");
415415 }
416416 let decoder = handle::ItemDecoder::new(Cursor::new(val), start_timestamp)?;
417417+ current_item_count += decoder.item_count();
418418+ if current_item_count > max_items {
419419+ return Ok(None);
420420+ }
417421 // tracing::info!(
418422 // "took {}ns to get block with size {}",
419423 // ts.elapsed().as_nanos(),
+6-2
server/src/main.rs
···11-use std::{ops::Deref, time::Duration, u64};
11+use std::{ops::Deref, time::Duration, u64, usize};
2233use itertools::Itertools;
44use rclite::Arc;
···300300 threads.push(std::thread::spawn(move || {
301301 tracing::info!("{}: migrating...", nsid.deref());
302302 let mut count = 0_u64;
303303- for hits in from.get_hits(&nsid, ..).chunks(100000).into_iter() {
303303+ for hits in from
304304+ .get_hits(&nsid, .., usize::MAX)
305305+ .chunks(100000)
306306+ .into_iter()
307307+ {
304308 to.ingest_events(hits.map(|hit| {
305309 count += 1;
306310 let hit = hit.expect("cant decode hit");