···
// let mut ts = CLOCK.now();
+
let map_block = move |(res, current_item_count)| -> AppResult<(Option<_>, usize)> {
if current_item_count >= max_items {
+
return Ok((None, current_item_count));
let mut key_reader = Cursor::new(key);
let start_timestamp = key_reader.read_varint::<u64>()?;
// let end_timestamp = key_reader.read_varint::<u64>()?;
···
// "stopped at block with timestamps {start_timestamp}..{end_timestamp} because {start_limit} is greater"
+
return Ok((None, current_item_count));
let decoder = handle::ItemDecoder::new(Cursor::new(val), start_timestamp)?;
+
let current_item_count = current_item_count + decoder.item_count();
// "took {}ns to get block with size {}",
// ts.elapsed().as_nanos(),
+
.take_while(move |item| {
+
item.as_ref().map_or(true, |item| {
+
item.timestamp <= end_limit && item.timestamp >= start_limit
+
.map(|res| res.map_err(AppError::from)),
+
let (blocks, counted) = handle
+
.map(|res| res.map_err(AppError::from))
+
(Vec::with_capacity(20), 0),
+
|(mut blocks, current_item_count), res| {
+
use itertools::FoldWhile::*;
+
match map_block((res, current_item_count)) {
+
Ok((Some(block), current_item_count)) => {
+
blocks.push(Ok(block));
+
Continue((blocks, current_item_count))
+
Ok((None, current_item_count)) => Done((blocks, current_item_count)),
+
Done((blocks, current_item_count))
+
"got blocks with size {}, item count {counted}",