Skip to content

Commit

Permalink
chore: improve data loading
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Aug 28, 2024
1 parent 187f07d commit b2b8299
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
37 changes: 20 additions & 17 deletions src/ic_oss_bucket/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,18 +1125,18 @@ pub mod fs {
let mut buf: Vec<FileChunk> = Vec::with_capacity(max_take as usize);
if max_take > 0 {
let mut filled = 0usize;
for (FileId(_, index), Chunk(chunk)) in r.borrow().range((
ops::Bound::Included(FileId(id, chunk_index)),
ops::Bound::Included(FileId(id, chunk_index + max_take - 1)),
)) {
filled += chunk.len();
if filled > MAX_FILE_SIZE_PER_CALL as usize {
break;
}
let m = r.borrow();
for i in chunk_index..(chunk_index + max_take) {
if let Some(Chunk(chunk)) = m.get(&FileId(id, i)) {
filled += chunk.len();
if filled > MAX_FILE_SIZE_PER_CALL as usize {
break;
}

buf.push(FileChunk(index, ByteBuf::from(chunk)));
if filled == MAX_FILE_SIZE_PER_CALL as usize {
break;
buf.push(FileChunk(i, ByteBuf::from(chunk)));
if filled == MAX_FILE_SIZE_PER_CALL as usize {
break;
}
}
}
}
Expand Down Expand Up @@ -1170,12 +1170,15 @@ pub mod fs {
return Ok(buf);
}

for (_, chunk) in r.borrow().range((
ops::Bound::Included(FileId(id, 0)),
ops::Bound::Included(FileId(id, chunks - 1)),
)) {
filled += chunk.0.len();
buf.extend_from_slice(&chunk.0);
let m = r.borrow();
for i in 0..chunks {
match m.get(&FileId(id, i)) {
None => Err(format!("file chunk not found: {}, {}", id, i))?,
Some(Chunk(chunk)) => {
filled += chunk.len();
buf.extend_from_slice(&chunk);
}
}
}

if filled as u64 != size {
Expand Down
17 changes: 10 additions & 7 deletions src/ic_oss_can/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ macro_rules! ic_oss_fs {
use ciborium::{from_reader, into_writer};
use ic_oss_types::file::{FileChunk, FileInfo, UpdateFileInput, CHUNK_SIZE};
use serde_bytes::ByteBuf;
use std::{cell::RefCell, collections::BTreeSet, ops};
use std::{cell::RefCell, collections::BTreeSet};

use super::FS_CHUNKS_STORE;
use $crate::types::*;
Expand Down Expand Up @@ -156,12 +156,15 @@ macro_rules! ic_oss_fs {
return Ok(buf);
}

for (_, chunk) in r.borrow().range((
ops::Bound::Included(FileId(id, 0)),
ops::Bound::Included(FileId(id, chunks - 1)),
)) {
filled += chunk.0.len();
buf.extend_from_slice(&chunk.0);
let m = r.borrow();
for i in 0..chunks {
match m.get(&FileId(id, i)) {
None => Err(format!("file chunk not found: {}, {}", id, i))?,
Some(Chunk(chunk)) => {
filled += chunk.len();
buf.extend_from_slice(&chunk);
}
}
}

if filled as u64 != size {
Expand Down

0 comments on commit b2b8299

Please sign in to comment.