Skip to content

Commit

Permalink
Use get_by_id returning key-value
Browse files Browse the repository at this point in the history
  • Loading branch information
msk committed Feb 13, 2024
1 parent 188eb48 commit 48108ab
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ oinq = { git = "https://github.com/petabi/oinq.git", tag = "0.9.1" }
reqwest = { version = "0.11", default-features = false, features = [
"rustls-tls-native-roots",
] }
review-database = { git = "https://github.com/petabi/review-database.git", rev = "5374afa9" }
review-database = { git = "https://github.com/petabi/review-database.git", rev = "037bd09b" }
roxy = { git = "https://github.com/aicers/roxy.git", tag = "0.2.1" }
rustls = "0.21"
rustls-native-certs = "0.6"
Expand Down
8 changes: 4 additions & 4 deletions src/graphql/customer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ impl CustomerQuery {

let store = crate::graphql::get_store(ctx).await?;
let map = store.customer_map();
let Some(value) = map.get_by_id(i)? else {
let Some((_key, value)) = map.get_by_id(i)? else {
return Err("no such customer".into());
};
Ok(Customer {
inner: bincode::DefaultOptions::new()
.deserialize(value.as_ref())
.deserialize(&value)
.map_err(|_| "invalid value in database")?,
})
}
Expand Down Expand Up @@ -551,9 +551,9 @@ pub fn get_customer_networks(db: &Store, customer_id: u32) -> Result<database::H
let mut hosts = vec![];
let mut networks = vec![];
let mut ip_ranges = vec![];
if let Some(value) = map.get_by_id(customer_id)? {
if let Some((_key, value)) = map.get_by_id(customer_id)? {
let customer = bincode::DefaultOptions::new()
.deserialize::<database::Customer>(value.as_ref())
.deserialize::<database::Customer>(&value)
.map_err(|_| "invalid value in database")?;
customer.networks.iter().for_each(|net| {
hosts.extend(net.network_group.hosts());
Expand Down
12 changes: 6 additions & 6 deletions src/graphql/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,12 +855,12 @@ fn convert_customer_input(
.as_str()
.parse::<u32>()
.context(format!("invalid ID: {}", id.as_str()))?;
let Some(value) = map.get_by_id(i)? else {
let Some((_key, value)) = map.get_by_id(i)? else {
bail!("no such customer")
};
customers.push(
codec
.deserialize(value.as_ref())
.deserialize(&value)
.context("invalid value in database")?,
);
}
Expand Down Expand Up @@ -929,11 +929,11 @@ fn convert_sensors(map: &IndexedMap, sensors: &[ID]) -> anyhow::Result<Vec<Strin
.as_str()
.parse::<u32>()
.context(format!("invalid ID: {}", id.as_str()))?;
let Some(value) = map.get_by_id(i)? else {
let Some((_key, value)) = map.get_by_id(i)? else {
bail!("no such sensor")
};
let value: super::node::Node = codec
.deserialize(value.as_ref())
.deserialize(&value)
.context("invalid value in database")?;

converted_sensors.push(value.hostname.clone());
Expand All @@ -952,12 +952,12 @@ fn convert_triage_input(
.as_str()
.parse::<u32>()
.context(format!("invalid ID: {}", id.as_str()))?;
let Some(value) = map.get_by_id(i)? else {
let Some((_key, value)) = map.get_by_id(i)? else {
bail!("no such customer")
};
triage_policies.push(
codec
.deserialize(value.as_ref())
.deserialize(&value)
.context("invalid value in database")?,
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ impl ModelDigest {
.get_by_id(self.inner.data_source_id as u32)
.map_err(|_| "failed to read data source")?
{
Some(value) => Ok(bincode::DefaultOptions::new()
.deserialize::<database::DataSource>(value.as_ref())?
Some((_key, value)) => Ok(bincode::DefaultOptions::new()
.deserialize::<database::DataSource>(&value)?
.into()),
None => Err("no such data source".into()),
}
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ impl Network {
let codec = bincode::DefaultOptions::new();
for &id in &self.inner.customer_ids {
#[allow(clippy::cast_sign_loss)] // u32 stored as i32 in database
let Some(value) = map.get_by_id(id)?
let Some((_key, value)) = map.get_by_id(id)?
else {
continue;
};
let customer = codec
.deserialize::<database::Customer>(value.as_ref())
.deserialize::<database::Customer>(&value)
.map_err(|_| "invalid value in database")?;
customers.push(customer.into());
}
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/node/crud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ impl NodeQuery {

let store = crate::graphql::get_store(ctx).await?;
let map = store.node_map();
let Some(value) = map.get_by_id(i)? else {
let Some((_key, value)) = map.get_by_id(i)? else {
return Err("no such node".into());
};
Ok(bincode::DefaultOptions::new()
.deserialize(value.as_ref())
.deserialize(&value)
.map_err(|_| "invalid value in database")?)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ impl SamplingPolicyQuery {

let store = crate::graphql::get_store(ctx).await?;
let map = store.sampling_policy_map();
let Some(value) = map.get_by_id(i)? else {
let Some((_key, value)) = map.get_by_id(i)? else {
return Err("no such sampling policy".into());
};
Ok(bincode::DefaultOptions::new()
.deserialize(value.as_ref())
.deserialize(&value)
.map_err(|_| "invalid value in database")?)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/triage/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ impl TriagePolicyQuery {

let store = crate::graphql::get_store(ctx).await?;
let map = store.triage_policy_map();
let Some(value) = map.get_by_id(i)? else {
let Some((_key, value)) = map.get_by_id(i)? else {
return Err("no such triage policy".into());
};
Ok(TriagePolicy {
inner: bincode::DefaultOptions::new()
.deserialize(value.as_ref())
.deserialize(&value)
.map_err(|_| "invalid value in database")?,
})
}
Expand Down

0 comments on commit 48108ab

Please sign in to comment.