From 8cd3e52d78bc7223f869ad64226976e968cbbfa0 Mon Sep 17 00:00:00 2001 From: Min Shao Date: Thu, 15 Feb 2024 12:29:20 -0800 Subject: [PATCH] Implement `FromKeyValue` for affected struct --- Cargo.toml | 2 +- src/graphql.rs | 5 ++--- src/graphql/allow_network.rs | 7 +++++++ src/graphql/block_network.rs | 7 +++++++ src/graphql/node.rs | 8 +++++++- src/graphql/sampling.rs | 9 ++++++++- src/graphql/template.rs | 8 +++++++- src/graphql/triage/response.rs | 9 ++++++++- 8 files changed, 47 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 289d5f72..6aa0461c 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 = "037bd09b" } +review-database = { git = "https://github.com/petabi/review-database.git", rev = "41ebf117" } 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.rs b/src/graphql.rs index 9fb9718a..89a87c7b 100644 --- a/src/graphql.rs +++ b/src/graphql.rs @@ -53,7 +53,6 @@ use num_traits::ToPrimitive; use review_database::{ self as database, types::FromKeyValue, Database, Direction, IterableMap, Role, Store, }; -use serde::de::DeserializeOwned; use std::{ cmp, collections::HashMap, @@ -449,7 +448,7 @@ fn load_edges( ) -> Result> where I: database::Iterable, - R: DeserializeOwned + database::UniqueKey, + R: database::types::FromKeyValue + database::UniqueKey, N: From + OutputType, A: ObjectType, NodesField: ConnectionNameType, @@ -506,7 +505,7 @@ fn collect_edges( ) -> (Vec>, bool) where I: database::Iterable, - R: DeserializeOwned + database::UniqueKey, + R: database::types::FromKeyValue + database::UniqueKey, { let edges: Box> = if let Some(cursor) = from { let mut edges: Box> = Box::new( diff --git a/src/graphql/allow_network.rs b/src/graphql/allow_network.rs index b2d0e307..70dbc5f2 100644 --- a/src/graphql/allow_network.rs +++ b/src/graphql/allow_network.rs @@ -9,6 +9,7 @@ use async_graphql::{ Context, InputObject, Object, Result, ID, }; use bincode::Options; +use database::types::FromKeyValue; use review_database::{self as database, Indexable, Indexed, IndexedMapUpdate, IterableMap, Store}; use serde::{Deserialize, Serialize}; @@ -140,6 +141,12 @@ pub(super) struct AllowNetwork { description: String, } +impl FromKeyValue for AllowNetwork { + fn from_key_value(_key: &[u8], value: &[u8]) -> anyhow::Result { + Ok(bincode::DefaultOptions::new().deserialize(value)?) + } +} + #[Object] impl AllowNetwork { async fn id(&self) -> ID { diff --git a/src/graphql/block_network.rs b/src/graphql/block_network.rs index 73484345..6db5a26d 100644 --- a/src/graphql/block_network.rs +++ b/src/graphql/block_network.rs @@ -7,6 +7,7 @@ use async_graphql::{ Context, InputObject, Object, Result, ID, }; use bincode::Options; +use database::types::FromKeyValue; use review_database::{self as database, Indexable, Indexed, IndexedMapUpdate, IterableMap, Store}; use serde::{Deserialize, Serialize}; use std::{borrow::Cow, sync::Arc}; @@ -139,6 +140,12 @@ pub(super) struct BlockNetwork { description: String, } +impl FromKeyValue for BlockNetwork { + fn from_key_value(_key: &[u8], value: &[u8]) -> anyhow::Result { + Ok(bincode::DefaultOptions::new().deserialize(value)?) + } +} + #[Object] impl BlockNetwork { async fn id(&self) -> ID { diff --git a/src/graphql/node.rs b/src/graphql/node.rs index 64c13ec3..182dc477 100644 --- a/src/graphql/node.rs +++ b/src/graphql/node.rs @@ -10,7 +10,7 @@ use chrono::{DateTime, TimeZone, Utc}; pub use crud::{get_customer_id_of_review_host, get_node_settings}; use input::NodeInput; use ipnet::Ipv4Net; -use review_database::{Indexable, Indexed}; +use review_database::{types::FromKeyValue, Indexable, Indexed}; use roxy::Process as RoxyProcess; use serde::{Deserialize, Serialize}; use std::{ @@ -212,6 +212,12 @@ impl Node { } } +impl FromKeyValue for Node { + fn from_key_value(_key: &[u8], value: &[u8]) -> anyhow::Result { + Ok(bincode::DefaultOptions::new().deserialize(value)?) + } +} + struct NodeTotalCount; #[Object] diff --git a/src/graphql/sampling.rs b/src/graphql/sampling.rs index 0fa2e80e..be4eb4d1 100644 --- a/src/graphql/sampling.rs +++ b/src/graphql/sampling.rs @@ -9,7 +9,8 @@ use bincode::Options; use chrono::{DateTime, Utc}; use oinq::RequestCode; use review_database::{ - Indexable, Indexed, IndexedMap, IndexedMapIterator, IndexedMapUpdate, IterableMap, + types::FromKeyValue, Indexable, Indexed, IndexedMap, IndexedMapIterator, IndexedMapUpdate, + IterableMap, }; use serde::{Deserialize, Serialize}; use std::{borrow::Cow, net::IpAddr}; @@ -85,6 +86,12 @@ pub(super) struct SamplingPolicy { creation_time: DateTime, } +impl FromKeyValue for SamplingPolicy { + fn from_key_value(_key: &[u8], value: &[u8]) -> anyhow::Result { + Ok(bincode::DefaultOptions::new().deserialize(value)?) + } +} + #[ComplexObject] impl SamplingPolicy { async fn id(&self) -> ID { diff --git a/src/graphql/template.rs b/src/graphql/template.rs index 4ce61445..3e182f9a 100644 --- a/src/graphql/template.rs +++ b/src/graphql/template.rs @@ -4,7 +4,7 @@ use async_graphql::{ Context, Enum, InputObject, Object, Result, SimpleObject, Union, }; use bincode::Options; -use review_database::{IterableMap, Map, MapIterator}; +use review_database::{types::FromKeyValue, IterableMap, Map, MapIterator}; use serde::{Deserialize, Serialize}; use std::convert::{TryFrom, TryInto}; @@ -193,6 +193,12 @@ enum Template { Unstructured(UnstructuredClusteringTemplate), } +impl FromKeyValue for Template { + fn from_key_value(_key: &[u8], value: &[u8]) -> anyhow::Result { + Ok(bincode::DefaultOptions::new().deserialize(value)?) + } +} + impl Template { fn name(&self) -> &str { match self { diff --git a/src/graphql/triage/response.rs b/src/graphql/triage/response.rs index 7ecd97d5..ff8a3a43 100644 --- a/src/graphql/triage/response.rs +++ b/src/graphql/triage/response.rs @@ -9,7 +9,8 @@ use async_graphql::{ use bincode::Options; use chrono::{DateTime, Utc}; use review_database::{ - Indexable, Indexed, IndexedMap, IndexedMapIterator, IndexedMapUpdate, IterableMap, + types::FromKeyValue, Indexable, Indexed, IndexedMap, IndexedMapIterator, IndexedMapUpdate, + IterableMap, }; use serde::{Deserialize, Serialize}; @@ -28,6 +29,12 @@ pub struct TriageResponse { last_modified_time: DateTime, } +impl FromKeyValue for TriageResponse { + fn from_key_value(_key: &[u8], value: &[u8]) -> anyhow::Result { + Ok(bincode::DefaultOptions::new().deserialize(value)?) + } +} + #[ComplexObject] impl TriageResponse { async fn id(&self) -> ID {