From 48108ab6ba686af878b40ade18d3549015a22092 Mon Sep 17 00:00:00 2001 From: Min Kim Date: Tue, 13 Feb 2024 14:13:09 -0800 Subject: [PATCH] Use `get_by_id` returning key-value --- Cargo.toml | 2 +- src/graphql/customer.rs | 8 ++++---- src/graphql/event.rs | 12 ++++++------ src/graphql/model.rs | 4 ++-- src/graphql/network.rs | 4 ++-- src/graphql/node/crud.rs | 4 ++-- src/graphql/sampling.rs | 4 ++-- src/graphql/triage/policy.rs | 4 ++-- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e38d8494..289d5f72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/graphql/customer.rs b/src/graphql/customer.rs index 60e32d1f..a5e1ea0d 100644 --- a/src/graphql/customer.rs +++ b/src/graphql/customer.rs @@ -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")?, }) } @@ -551,9 +551,9 @@ pub fn get_customer_networks(db: &Store, customer_id: u32) -> Result(value.as_ref()) + .deserialize::(&value) .map_err(|_| "invalid value in database")?; customer.networks.iter().for_each(|net| { hosts.extend(net.network_group.hosts()); diff --git a/src/graphql/event.rs b/src/graphql/event.rs index 1d11f1fa..064e6931 100644 --- a/src/graphql/event.rs +++ b/src/graphql/event.rs @@ -855,12 +855,12 @@ fn convert_customer_input( .as_str() .parse::() .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")?, ); } @@ -929,11 +929,11 @@ fn convert_sensors(map: &IndexedMap, sensors: &[ID]) -> anyhow::Result() .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()); @@ -952,12 +952,12 @@ fn convert_triage_input( .as_str() .parse::() .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")?, ); } diff --git a/src/graphql/model.rs b/src/graphql/model.rs index 4251a772..d24fbe73 100644 --- a/src/graphql/model.rs +++ b/src/graphql/model.rs @@ -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::(value.as_ref())? + Some((_key, value)) => Ok(bincode::DefaultOptions::new() + .deserialize::(&value)? .into()), None => Err("no such data source".into()), } diff --git a/src/graphql/network.rs b/src/graphql/network.rs index 89fbb489..e6da0f9c 100644 --- a/src/graphql/network.rs +++ b/src/graphql/network.rs @@ -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::(value.as_ref()) + .deserialize::(&value) .map_err(|_| "invalid value in database")?; customers.push(customer.into()); } diff --git a/src/graphql/node/crud.rs b/src/graphql/node/crud.rs index bedbb39a..0c484f0c 100644 --- a/src/graphql/node/crud.rs +++ b/src/graphql/node/crud.rs @@ -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")?) } } diff --git a/src/graphql/sampling.rs b/src/graphql/sampling.rs index ec489eac..0fa2e80e 100644 --- a/src/graphql/sampling.rs +++ b/src/graphql/sampling.rs @@ -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")?) } } diff --git a/src/graphql/triage/policy.rs b/src/graphql/triage/policy.rs index c0997c5c..7c715184 100644 --- a/src/graphql/triage/policy.rs +++ b/src/graphql/triage/policy.rs @@ -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")?, }) }