Skip to content

Commit

Permalink
Simplify fast object retrieval data handling
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Dec 9, 2024
1 parent 436f462 commit 165c21a
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions shared/subspace-data-retrieval/src/object_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ where
read_records_data.truncate(RawRecord::SIZE - 2);
}

let data_length = self.decode_data_length(
&read_records_data[piece_offset as usize..],
piece_index,
piece_offset,
)?;
// Discard piece data before the offset
let mut data = read_records_data[piece_offset as usize..].to_vec();
drop(read_records_data);

let data_length = self.decode_data_length(&data, piece_index, piece_offset)?;

let data_length = if let Some(data_length) = data_length {
data_length
Expand All @@ -309,14 +309,10 @@ where
.read_piece(next_source_piece_index, piece_index, piece_offset)
.await?;
next_source_piece_index = next_source_piece_index.next_source_index();
read_records_data.extend(piece.record().to_raw_record_chunks().flatten().copied());
data.extend(piece.record().to_raw_record_chunks().flatten().copied());

self.decode_data_length(
&read_records_data[piece_offset as usize..],
piece_index,
piece_offset,
)?
.expect("Extra RawRecord is larger than the length encoding; qed")
self.decode_data_length(&data, piece_index, piece_offset)?
.expect("Extra RawRecord is larger than the length encoding; qed")
} else {
trace!(
piece_position_in_segment,
Expand Down Expand Up @@ -347,10 +343,6 @@ where
return Ok(None);
}

// Discard piece data before the offset
let mut data = read_records_data[piece_offset as usize..].to_vec();
drop(read_records_data);

// Read more pieces until we have enough data
if data_length as usize > data.len() {
let remaining_piece_count =
Expand Down

0 comments on commit 165c21a

Please sign in to comment.