Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove byte_map in Resource #95

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,9 @@ impl Pipeline {
let _enter = step_span.enter();
debug!("start");
match step {
Step::Load { key, with, .. } => {
Step::Load { key, .. } => {
if let Some(value) = resource.get_value(&index) {
store.set(key.to_string(), value.clone());
} else if let Some(bytes) = resource.get_bytes(&index) {
let value = match with {
EnumLoader::Template => TemplateLoader::load(bytes),
EnumLoader::Json => JsonLoader::load(bytes),
EnumLoader::TextWithFrontmatter => {
TextWithFrontmatterLoader::load(bytes)
}
EnumLoader::Blob => BlobLoader::load(bytes),
EnumLoader::Text => TextLoader::load(bytes),
EnumLoader::Yaml => YamlLoader::load(bytes),
}
.with_context(|| {
format!(
"failed to load {} with {:?} Loader (steps index: {})",
key, self.entry.type_, index
)
})?;
store.set(key.to_string(), value);
} else {
anyhow::bail!("no value prefetched for key {}", key);
}
Expand Down
10 changes: 1 addition & 9 deletions src/pipeline/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use super::Pipeline;
/// One resource instance is created per [`Pipeline`](crate::pipeline::Pipeline).
#[derive(Debug)]
pub struct Resource {
byte_map: HashMap<usize, Vec<u8>>,
value_map: HashMap<usize, Value>,
}

Expand Down Expand Up @@ -59,14 +58,7 @@ impl Resource {
info!("finish preload");
}
}
Ok(Self {
byte_map,
value_map,
})
}

pub fn get_bytes(&self, key: &usize) -> Option<&[u8]> {
self.byte_map.get(key).map(|v| &v[..])
Ok(Self { value_map })
}

pub fn get_value(&self, key: &usize) -> Option<&Value> {
Expand Down
Loading