From a1e1eb5aaed08fe3601cad9d953e8d78b844d2b0 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Tue, 2 Jul 2019 10:47:14 -0400 Subject: [PATCH 01/48] implemented get links system --- core/src/action.rs | 2 + core/src/network/actions/get_links_count.rs | 73 +++++++++++++++++++ core/src/network/actions/mod.rs | 2 + core/src/network/handler/query.rs | 7 +- core/src/network/query.rs | 2 + core/src/network/reducers/mod.rs | 3 + .../reducers/respond_get_links_count.rs | 63 ++++++++++++++++ core/src/network/state.rs | 5 ++ 8 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 core/src/network/actions/get_links_count.rs create mode 100644 core/src/network/reducers/respond_get_links_count.rs diff --git a/core/src/action.rs b/core/src/action.rs index c657336acd..dbe9e4b2ba 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -157,7 +157,9 @@ pub enum Action { /// Last string is the stringified process unique id of this `hdk::get_links` call. GetLinks(GetLinksKey), GetLinksTimeout(GetLinksKey), + GetLinksCount(GetLinksKey), RespondGetLinks((QueryEntryData, Vec<(Address, CrudStatus)>, String, String)), + RespondGetLinksCount((QueryEntryData, usize, String, String)), HandleGetLinksResult((Vec<(Address, CrudStatus)>, GetLinksKey)), /// Makes the network module send a direct (node-to-node) message diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs new file mode 100644 index 0000000000..8dd8e71026 --- /dev/null +++ b/core/src/network/actions/get_links_count.rs @@ -0,0 +1,73 @@ +use crate::{ + action::{Action, ActionWrapper, GetLinksKey}, + context::Context, + instance::dispatch_action, +}; +use futures::{ + future::Future, + task::{LocalWaker, Poll}, +}; +use holochain_core_types::{error::HcResult, time::Timeout}; +use holochain_persistence_api::cas::content::Address; +use snowflake::ProcessUniqueId; +use std::{pin::Pin, sync::Arc, thread}; + +/// GetLinks Action Creator +/// This is the network version of get_links that makes the network module start +/// a look-up process. +pub async fn get_links( + context: Arc, + address: Address, + link_type: String, + tag: String, + timeout: Timeout, +) -> HcResult { + let key = GetLinksKey { + base_address: address.clone(), + link_type: link_type.clone(), + tag: tag.clone(), + id: ProcessUniqueId::new().to_string(), + }; + let action_wrapper = ActionWrapper::new(Action::GetLinksCount(key.clone())); + dispatch_action(context.action_channel(), action_wrapper.clone()); + + let key_inner = key.clone(); + let context_inner = context.clone(); + let _ = thread::spawn(move || { + thread::sleep(timeout.into()); + let action_wrapper = ActionWrapper::new(Action::GetLinksTimeout(key_inner)); + dispatch_action(context_inner.action_channel(), action_wrapper.clone()); + }); + + await!(GetLinksCountFuture { + context: context.clone(), + key + }) +} + +/// GetLinksFuture resolves to a HcResult>. +/// Tracks the state of the network module +pub struct GetLinksCountFuture { + context: Arc, + key: GetLinksKey, +} + +impl Future for GetLinksCountFuture { + type Output = HcResult; + + fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { + let state = self.context.state().unwrap().network(); + if let Err(error) = state.initialized() { + return Poll::Ready(Err(error)); + } + // + // TODO: connect the waker to state updates for performance reasons + // See: https://github.com/holochain/holochain-rust/issues/314 + // + lw.wake(); + match state.get_links_results_count.get(&self.key) { + Some(Some(result)) => Poll::Ready(result.clone()), + _ => Poll::Pending, + } + } +} diff --git a/core/src/network/actions/mod.rs b/core/src/network/actions/mod.rs index b8757b30e2..0fe1fc607c 100644 --- a/core/src/network/actions/mod.rs +++ b/core/src/network/actions/mod.rs @@ -1,6 +1,7 @@ pub mod custom_send; pub mod get_entry; pub mod get_links; +pub mod get_links_count; pub mod get_validation_package; pub mod initialize_network; pub mod publish; @@ -14,4 +15,5 @@ pub enum ActionResponse { RespondGet(HcResult<()>), RespondFetch(HcResult<()>), RespondGetLinks(HcResult<()>), + RespondGetLinksCount(HcResult<()>) } diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index 4aadc04a5a..119f12d7f1 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -82,7 +82,12 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc link_type.clone(), tag.clone(), ))) - } + }, + Ok(NetworkQuery::GetLinksCount(link_type,tag)) => + { + let links_count = get_links(&context,query_data.entry_address.clone(),link_type.clone(),tag.clone()).len(); + ActionWrapper::new(Action::RespondGetLinksCount((query_data,links_count,link_type.clone(),tag.clone()))) + }, Ok(NetworkQuery::GetEntry) => { let maybe_entry = get_entry(&context, query_data.entry_address.clone()); ActionWrapper::new(Action::RespondGet((query_data, maybe_entry))) diff --git a/core/src/network/query.rs b/core/src/network/query.rs index 160efcd98e..5ae64a628f 100644 --- a/core/src/network/query.rs +++ b/core/src/network/query.rs @@ -6,10 +6,12 @@ use holochain_persistence_api::cas::content::Address; pub enum NetworkQuery { GetEntry, GetLinks(String, String), + GetLinksCount(String,String) } #[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] pub enum NetworkQueryResult { Entry(Option), Links(Vec<(Address, CrudStatus)>, String, String), + LinksCount(usize, String, String) } diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index 0c3ec7c2eb..1115b12804 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -3,6 +3,7 @@ pub mod get_links; pub mod get_validation_package; pub mod handle_custom_send_response; pub mod handle_get_links_result; +pub mod respond_get_links_count; pub mod handle_get_result; pub mod handle_get_validation_package; pub mod init; @@ -31,6 +32,7 @@ use crate::{ respond_fetch::reduce_respond_fetch_data, respond_get::reduce_respond_get, respond_get_links::reduce_respond_get_links, + respond_get_links_count::reduce_respond_get_links_count, send_direct_message::{reduce_send_direct_message, reduce_send_direct_message_timeout}, }, state::NetworkState, @@ -65,6 +67,7 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::RespondFetch(_) => Some(reduce_respond_fetch_data), Action::RespondGet(_) => Some(reduce_respond_get), Action::RespondGetLinks(_) => Some(reduce_respond_get_links), + Action::RespondGetLinksCount(_) => Some(reduce_respond_get_links_count), Action::SendDirectMessage(_) => Some(reduce_send_direct_message), Action::SendDirectMessageTimeout(_) => Some(reduce_send_direct_message_timeout), _ => None, diff --git a/core/src/network/reducers/respond_get_links_count.rs b/core/src/network/reducers/respond_get_links_count.rs new file mode 100644 index 0000000000..fab493ad08 --- /dev/null +++ b/core/src/network/reducers/respond_get_links_count.rs @@ -0,0 +1,63 @@ +use crate::{ + action::ActionWrapper, + network::{ + actions::ActionResponse, query::NetworkQueryResult, reducers::send, state::NetworkState, + }, + state::State, +}; +use holochain_core_types::error::HolochainError; +use holochain_json_api::json::JsonString; +use holochain_net::connection::json_protocol::{ + JsonProtocol, QueryEntryData, QueryEntryResultData, +}; + + +/// Send back to network a HandleQueryEntryResult, no matter what. +/// Will return an empty content field if it actually doesn't have the data. +fn reduce_respond_get_links_count_inner( + network_state: &mut NetworkState, + query_data: &QueryEntryData, + links_count: usize, + link_type: String, + tag: String, +) -> Result<(), HolochainError> { + network_state.initialized()?; + let query_result_json: JsonString = + NetworkQueryResult::LinksCount(links_count.clone(), link_type, tag).into(); + send( + network_state, + JsonProtocol::HandleQueryEntryResult(QueryEntryResultData { + request_id: query_data.request_id.clone(), + requester_agent_id: query_data.requester_agent_id.clone(), + dna_address: network_state.dna_address.clone().unwrap(), + responder_agent_id: network_state.agent_id.clone().unwrap().into(), + entry_address: query_data.entry_address.clone().into(), + query_result: query_result_json.to_string().into_bytes(), + }), + ) +} + +pub fn reduce_respond_get_links_count( + network_state: &mut NetworkState, + _root_state: &State, + action_wrapper: &ActionWrapper, +) { + let action = action_wrapper.action(); + let (query_data, links_count, link_type, tag) = + unwrap_to!(action => crate::action::Action::RespondGetLinksCount); + let result = reduce_respond_get_links_count_inner( + network_state, + query_data, + links_count.clone(), + link_type.clone(), + tag.clone(), + ); + + network_state.actions.insert( + action_wrapper.clone(), + ActionResponse::RespondGetLinksCount(match result { + Ok(_) => Ok(()), + Err(e) => Err(HolochainError::ErrorGeneric(e.to_string())), + }), + ); +} diff --git a/core/src/network/state.rs b/core/src/network/state.rs index 5a37e6f090..642b1d39aa 100644 --- a/core/src/network/state.rs +++ b/core/src/network/state.rs @@ -30,6 +30,8 @@ type GetEntryWithMetaResult = Option, Holo /// Some(Ok(_)): we got the list of links type GetLinksResult = Option, HolochainError>>; +type GetLinksResultCount = Option>; + /// This represents the state of a get_validation_package network process: /// None: process started, but no response yet from the network /// Some(Err(_)): there was a problem at some point @@ -59,6 +61,8 @@ pub struct NetworkState { /// None means that we are still waiting for a result from the network. pub get_links_results: HashMap, + pub get_links_results_count : HashMap, + /// Here we store the results of get validation package processes. /// None means that we are still waiting for a result from the network. pub get_validation_package_results: HashMap, @@ -88,6 +92,7 @@ impl NetworkState { get_entry_with_meta_results: HashMap::new(), get_links_results: HashMap::new(), + get_links_results_count : HashMap::new(), get_validation_package_results: HashMap::new(), direct_message_connections: HashMap::new(), custom_direct_message_replys: HashMap::new(), From 35be08ab1aae9d8748253e718d8db083b369a0b5 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Tue, 2 Jul 2019 10:56:10 -0400 Subject: [PATCH 02/48] Handle get links result implemented --- core/src/action.rs | 1 + core/src/network/actions/get_links_count.rs | 4 ++-- .../reducers/handle_get_links_result_count.rs | 13 +++++++++++++ core/src/network/reducers/mod.rs | 3 +++ core/src/network/state.rs | 2 +- 5 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 core/src/network/reducers/handle_get_links_result_count.rs diff --git a/core/src/action.rs b/core/src/action.rs index dbe9e4b2ba..3dc5f53df3 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -161,6 +161,7 @@ pub enum Action { RespondGetLinks((QueryEntryData, Vec<(Address, CrudStatus)>, String, String)), RespondGetLinksCount((QueryEntryData, usize, String, String)), HandleGetLinksResult((Vec<(Address, CrudStatus)>, GetLinksKey)), + HandleGetLinksResultCount((usize, GetLinksKey)), /// Makes the network module send a direct (node-to-node) message /// to the address given in [DirectMessageData](struct.DirectMessageData.html) diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs index 8dd8e71026..2c1848f2f9 100644 --- a/core/src/network/actions/get_links_count.rs +++ b/core/src/network/actions/get_links_count.rs @@ -21,7 +21,7 @@ pub async fn get_links( link_type: String, tag: String, timeout: Timeout, -) -> HcResult { +) -> HcResult { let key = GetLinksKey { base_address: address.clone(), link_type: link_type.clone(), @@ -53,7 +53,7 @@ pub struct GetLinksCountFuture { } impl Future for GetLinksCountFuture { - type Output = HcResult; + type Output = HcResult; fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { let state = self.context.state().unwrap().network(); diff --git a/core/src/network/reducers/handle_get_links_result_count.rs b/core/src/network/reducers/handle_get_links_result_count.rs new file mode 100644 index 0000000000..bd17ad343b --- /dev/null +++ b/core/src/network/reducers/handle_get_links_result_count.rs @@ -0,0 +1,13 @@ +use crate::{action::ActionWrapper, network::state::NetworkState, state::State}; + +pub fn reduce_handle_get_links_count( + network_state: &mut NetworkState, + _root_state: &State, + action_wrapper: &ActionWrapper, +) { + let action = action_wrapper.action(); + let (links_count, key) = unwrap_to!(action => crate::action::Action::HandleGetLinksResultCount); + network_state + .get_links_results_count + .insert(key.clone(), Some(Ok(links_count.clone()))); +} diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index 1115b12804..d702e73713 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -3,6 +3,7 @@ pub mod get_links; pub mod get_validation_package; pub mod handle_custom_send_response; pub mod handle_get_links_result; +pub mod handle_get_links_result_count; pub mod respond_get_links_count; pub mod handle_get_result; pub mod handle_get_validation_package; @@ -24,6 +25,7 @@ use crate::{ get_validation_package::reduce_get_validation_package, handle_custom_send_response::reduce_handle_custom_send_response, handle_get_links_result::reduce_handle_get_links_result, + handle_get_links_result_count::reduce_handle_get_links_count, handle_get_result::reduce_handle_get_result, handle_get_validation_package::reduce_handle_get_validation_package, init::reduce_init, @@ -61,6 +63,7 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::HandleGetResult(_) => Some(reduce_handle_get_result), Action::HandleGetLinksResult(_) => Some(reduce_handle_get_links_result), Action::HandleGetValidationPackage(_) => Some(reduce_handle_get_validation_package), + Action::HandleGetLinksResultCount(_) => Some(reduce_handle_get_links_count), Action::InitNetwork(_) => Some(reduce_init), Action::Publish(_) => Some(reduce_publish), Action::ResolveDirectConnection(_) => Some(reduce_resolve_direct_connection), diff --git a/core/src/network/state.rs b/core/src/network/state.rs index 642b1d39aa..041576b111 100644 --- a/core/src/network/state.rs +++ b/core/src/network/state.rs @@ -30,7 +30,7 @@ type GetEntryWithMetaResult = Option, Holo /// Some(Ok(_)): we got the list of links type GetLinksResult = Option, HolochainError>>; -type GetLinksResultCount = Option>; +type GetLinksResultCount = Option>; /// This represents the state of a get_validation_package network process: /// None: process started, but no response yet from the network From 36003f035314b891afc7fb9ba116e0b71fbd0805 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Tue, 2 Jul 2019 11:12:03 -0400 Subject: [PATCH 03/48] put handle get links count --- core/src/network/handler/query.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index 119f12d7f1..fd339e539d 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -128,6 +128,17 @@ pub fn handle_query_entry_result(query_result_data: QueryEntryResultData, contex id: query_result_data.request_id.clone(), }, ))) + }, + Ok(NetworkQueryResult::LinksCount(links_count, link_type, tag)) => { + ActionWrapper::new(Action::HandleGetLinksResultCount(( + links_count, + GetLinksKey { + base_address: query_result_data.entry_address.clone(), + link_type: link_type.clone(), + tag: tag.clone(), + id: query_result_data.request_id.clone(), + }, + ))) } err => { context.log(format!( From 2f1e01628cd58fc51cdbfb9b2b25d3ff05f6da50 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Tue, 2 Jul 2019 13:21:20 -0400 Subject: [PATCH 04/48] Implemented nucleaus --- core/src/network/actions/get_links_count.rs | 2 +- core/src/nucleus/ribosome/api/get_links.rs | 3 ++ .../nucleus/ribosome/api/get_links_count.rs | 36 +++++++++++++++++++ core/src/nucleus/ribosome/api/mod.rs | 1 + core/src/workflows/get_links_count.rs | 18 ++++++++++ core/src/workflows/mod.rs | 1 + wasm_utils/src/api_serialization/get_links.rs | 10 +++++- 7 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 core/src/nucleus/ribosome/api/get_links_count.rs create mode 100644 core/src/workflows/get_links_count.rs diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs index 2c1848f2f9..daebb1a2f0 100644 --- a/core/src/network/actions/get_links_count.rs +++ b/core/src/network/actions/get_links_count.rs @@ -15,7 +15,7 @@ use std::{pin::Pin, sync::Arc, thread}; /// GetLinks Action Creator /// This is the network version of get_links that makes the network module start /// a look-up process. -pub async fn get_links( +pub async fn get_links_count( context: Arc, address: Address, link_type: String, diff --git a/core/src/nucleus/ribosome/api/get_links.rs b/core/src/nucleus/ribosome/api/get_links.rs index 6638a4c1ce..82b1397982 100644 --- a/core/src/nucleus/ribosome/api/get_links.rs +++ b/core/src/nucleus/ribosome/api/get_links.rs @@ -31,11 +31,14 @@ pub fn invoke_get_links(runtime: &mut Runtime, args: &RuntimeArgs) -> ZomeApiRes } }; + let result = context.block_on(get_link_result_workflow(&context, &input)); runtime.store_result(result) } + + #[cfg(test)] pub mod tests { use std::sync::Arc; diff --git a/core/src/nucleus/ribosome/api/get_links_count.rs b/core/src/nucleus/ribosome/api/get_links_count.rs new file mode 100644 index 0000000000..3353be2d02 --- /dev/null +++ b/core/src/nucleus/ribosome/api/get_links_count.rs @@ -0,0 +1,36 @@ +use crate::{ + nucleus::ribosome::{api::ZomeApiResult, Runtime}, + workflows::get_links_count::get_link_result_count_workflow, +}; +use holochain_wasm_utils::api_serialization::get_links::GetLinksArgs; +use std::convert::TryFrom; +use wasmi::{RuntimeArgs, RuntimeValue}; + + + +pub fn invoke_get_links_count(runtime: &mut Runtime, args: &RuntimeArgs) -> ZomeApiResult { + let context = runtime.context()?; + // deserialize args + let args_str = runtime.load_json_string_from_args(&args); + let input = match GetLinksArgs::try_from(args_str.clone()) { + Ok(input) => { + context.log(format!( + "log/get_links: invoke_get_links called with {:?}", + input, + )); + input + } + Err(_) => { + context.log(format!( + "err/zome: invoke_get_links failed to deserialize GetLinksArgs: {:?}", + args_str + )); + return ribosome_error_code!(ArgumentDeserializationFailed); + } + }; + + + let result = context.block_on(get_link_result_count_workflow(context.clone(), &input)); + + runtime.store_result(result) +} \ No newline at end of file diff --git a/core/src/nucleus/ribosome/api/mod.rs b/core/src/nucleus/ribosome/api/mod.rs index ea72df9dcf..17d040304a 100644 --- a/core/src/nucleus/ribosome/api/mod.rs +++ b/core/src/nucleus/ribosome/api/mod.rs @@ -8,6 +8,7 @@ pub mod emit_signal; pub mod entry_address; pub mod get_entry; pub mod get_links; +pub mod get_links_count; pub mod init_globals; pub mod link_entries; #[macro_use] diff --git a/core/src/workflows/get_links_count.rs b/core/src/workflows/get_links_count.rs new file mode 100644 index 0000000000..4ca4ca911b --- /dev/null +++ b/core/src/workflows/get_links_count.rs @@ -0,0 +1,18 @@ +use crate::{ + context::Context, network::actions::get_links_count::get_links_count +}; + +use holochain_core_types::error::HolochainError; +use holochain_wasm_utils::api_serialization::get_links::{GetLinksArgs,GetLinksResultCount}; +use std::sync::Arc; + +pub async fn get_link_result_count_workflow<'a>( + context: Arc, + link_args: &'a GetLinksArgs, +) -> Result { + let links_count = await!(get_links_count(context, link_args.entry_address.clone(),link_args.link_type.clone(),link_args.tag.clone(),link_args.options.timeout.clone()))?; + //get links based on status request, all for everything, deleted for deleted links and live for active links + + + Ok(GetLinksResultCount{count:links_count}) +} \ No newline at end of file diff --git a/core/src/workflows/mod.rs b/core/src/workflows/mod.rs index ee91953f4c..e29b66e9dc 100644 --- a/core/src/workflows/mod.rs +++ b/core/src/workflows/mod.rs @@ -2,6 +2,7 @@ pub mod application; pub mod author_entry; pub mod get_entry_result; pub mod get_link_result; +pub mod get_links_count; pub mod handle_custom_direct_message; pub mod hold_entry; pub mod hold_entry_remove; diff --git a/wasm_utils/src/api_serialization/get_links.rs b/wasm_utils/src/api_serialization/get_links.rs index 6e2630454c..334ab6b300 100644 --- a/wasm_utils/src/api_serialization/get_links.rs +++ b/wasm_utils/src/api_serialization/get_links.rs @@ -7,7 +7,7 @@ pub struct GetLinksArgs { pub entry_address: Address, pub link_type: String, pub tag: String, - pub options: GetLinksOptions, + pub options: GetLinksOptions } #[derive(Deserialize, Debug, Serialize, DefaultJson, Clone, PartialEq, Eq, Hash)] @@ -38,6 +38,9 @@ impl Default for GetLinksOptions { } } + + + #[derive(Deserialize, Serialize, Debug, DefaultJson)] pub struct LinksResult { pub address: Address, @@ -51,6 +54,11 @@ pub struct GetLinksResult { links: Vec, } +#[derive(Deserialize, Serialize, Debug, DefaultJson)] +pub struct GetLinksResultCount { + pub count: usize +} + impl GetLinksResult { pub fn new(links: Vec) -> GetLinksResult { GetLinksResult { links } From bac47999b0960e38450e2d71f9242a9d3c3c7f19 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Tue, 2 Jul 2019 14:13:13 -0400 Subject: [PATCH 05/48] Implementing filter on get_links --- app_spec/test/test.js | 58 +++++++++++++++++++ app_spec/zomes/simple/code/src/lib.rs | 14 +++++ .../zomes/simple/code/src/lib.rs | 10 ++++ core/src/dht/dht_store.rs | 2 + core/src/nucleus/ribosome/api/get_links.rs | 4 +- .../nucleus/ribosome/api/get_links_count.rs | 4 +- core/src/nucleus/ribosome/api/mod.rs | 4 ++ hdk-rust/src/api/get_links.rs | 46 ++++++++++++++- hdk-rust/src/api/mod.rs | 3 +- 9 files changed, 140 insertions(+), 5 deletions(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index 2337d780a2..e80bfe1dcf 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -851,6 +851,64 @@ scenario('get_links_crud', async (s, t, { alice, bob }) => { t.equal("deleted",bob_posts_all.Ok.links[1].status); +}) + +scenario('get_links_crud_count', async (s, t, { alice, bob }) => { + + //commits an entry and creates two links for alice + await alice.callSync("simple", "create_link", + { "base": alice.agentId ,"target": "Holo world" } + ); + const alice_result = await alice.callSync("simple", "create_link", + { "base": alice.agentId ,"target": "Holo world 2" } + ); + + //get posts for alice from alice + const alice_posts_live= await alice.call("simple","get_my_links_count", + { + "base" : alice.agentId,"status_request":"Live" + }) + + //get posts for alice from bob + const bob_posts_live= await bob.call("simple","get_my_links_count", + { + "base" : alice.agentId, + "status_request":"Live" + }) + + //make sure all our links are live and they are two of them + t.equal(2,alice_posts_live.Ok.count); + t.equal(2,bob_posts_live.Ok.links.count); + + + ////delete the holo world post from the links alice created + await alice.callSync("simple","delete_link", + { + "base" : alice.agentId, + "target" : "Holo world" + }); + + //get all posts with a deleted status from bob + const bob_posts_deleted = await bob.call("simple","get_my_links_count", + { + "base" : alice.agentId, + "status_request" : "Deleted" + }); + + // get all posts with a deleted status from alice + const alice_posts_deleted = await alice.call("simple","get_my_links_count", + { + "base" : alice.agentId, + "status_request" : "Deleted" + }); + + //make sure only 1 is returned and it has a status of deleted + t.equal(1,alice_posts_deleted.Ok.count); + t.equal(1,bob_posts_deleted.Ok.count); + + + + }) scenario('create/get_post roundtrip', async (s, t, { alice }) => { diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index 96c76704cb..e73188e432 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -74,6 +74,15 @@ pub fn handle_get_my_links(agent : Address,status_request:Option) ->ZomeApiResult +{ + let options = GetLinksOptions{ + status_request : status_request.unwrap_or(LinksStatusRequestKind::All), + ..GetLinksOptions::default() + }; + hdk::get_links_with_options(&agent, LinkMatch::Exactly("authored_posts"), LinkMatch::Any,options) +} + pub fn handle_test_emit_signal(message: String) -> ZomeApiResult<()> { #[derive(Debug, Serialize, Deserialize, DefaultJson)] struct SignalPayload { @@ -150,6 +159,11 @@ define_zome! { outputs: |result: ZomeApiResult|, handler: handle_get_my_links } + get_my_links_count: { + inputs: |base: Address,status_request:Option|, + outputs: |result: ZomeApiResult|, + handler: handle_get_my_links_count + } encrypt :{ inputs : |payload: String|, outputs: |result: ZomeApiResult|, diff --git a/app_spec_proc_macro/zomes/simple/code/src/lib.rs b/app_spec_proc_macro/zomes/simple/code/src/lib.rs index 7a2ad65831..2758bca56d 100644 --- a/app_spec_proc_macro/zomes/simple/code/src/lib.rs +++ b/app_spec_proc_macro/zomes/simple/code/src/lib.rs @@ -124,6 +124,16 @@ pub mod simple { hdk::get_links_with_options(&base, LinkMatch::Exactly("authored_posts"), LinkMatch::Any,options) } + #[zome_fn("hc_public")] + pub fn get_my_links_count(base: Address,status_request : Option) -> ZomeApiResult + { + let options = GetLinksOptions{ + status_request : status_request.unwrap_or(LinksStatusRequestKind::All), + ..GetLinksOptions::default() + }; + hdk::get_links_with_count_options(&base, LinkMatch::Exactly("authored_posts"), LinkMatch::Any,options) + } + #[zome_fn("hc_public")] pub fn test_emit_signal(message: String) -> ZomeApiResult<()> { #[derive(Debug, Serialize, Deserialize, DefaultJson)] diff --git a/core/src/dht/dht_store.rs b/core/src/dht/dht_store.rs index ec3a1c837d..9a7bd4fc26 100644 --- a/core/src/dht/dht_store.rs +++ b/core/src/dht/dht_store.rs @@ -93,6 +93,7 @@ impl DhtStore { address: Address, link_type: String, tag: String, + crud_filter : Option ) -> Result, HolochainError> { let get_links_query = create_get_links_eavi_query(address, link_type, tag)?; let filtered = self.meta_storage.read()?.fetch_eavi(&get_links_query)?; @@ -102,6 +103,7 @@ impl DhtStore { Attribute::LinkTag(_, _) => (s, CrudStatus::Live), _ => (s, CrudStatus::Deleted), }) + .filter(|link_crud| crud_filter.map(|crud| crud==link_crud.1).unwrap_or(true)) .collect()) } diff --git a/core/src/nucleus/ribosome/api/get_links.rs b/core/src/nucleus/ribosome/api/get_links.rs index 82b1397982..b23d6c7336 100644 --- a/core/src/nucleus/ribosome/api/get_links.rs +++ b/core/src/nucleus/ribosome/api/get_links.rs @@ -107,7 +107,7 @@ pub mod tests { instance.initialize_context(context) } - fn add_links(initialized_context: Arc, links: Vec) { + pub fn add_links(initialized_context: Arc, links: Vec) { links.iter().for_each(|link| { assert!(initialized_context //commit the AddLink entry first .block_on(commit_entry( @@ -125,7 +125,7 @@ pub mod tests { }); } - fn get_links( + pub fn get_links( initialized_context: Arc, base: &Address, link_type: LinkMatch, diff --git a/core/src/nucleus/ribosome/api/get_links_count.rs b/core/src/nucleus/ribosome/api/get_links_count.rs index 3353be2d02..5aad7d74a9 100644 --- a/core/src/nucleus/ribosome/api/get_links_count.rs +++ b/core/src/nucleus/ribosome/api/get_links_count.rs @@ -33,4 +33,6 @@ pub fn invoke_get_links_count(runtime: &mut Runtime, args: &RuntimeArgs) -> Zome let result = context.block_on(get_link_result_count_workflow(context.clone(), &input)); runtime.store_result(result) -} \ No newline at end of file +} + + diff --git a/core/src/nucleus/ribosome/api/mod.rs b/core/src/nucleus/ribosome/api/mod.rs index 17d040304a..92a7fca031 100644 --- a/core/src/nucleus/ribosome/api/mod.rs +++ b/core/src/nucleus/ribosome/api/mod.rs @@ -36,6 +36,7 @@ use crate::nucleus::ribosome::{ entry_address::invoke_entry_address, get_entry::invoke_get_entry, get_links::invoke_get_links, + get_links_count::invoke_get_links_count, init_globals::invoke_init_globals, keystore::{ invoke_keystore_derive_key, invoke_keystore_derive_seed, @@ -95,6 +96,9 @@ link_zome_api! { /// Retrieve links from the DHT "hc_get_links", GetLinks, invoke_get_links; + //Retrieve link count from DHT + "hc_get_links_count", GetLinksCount, invoke_get_links_count; + /// Query the local chain for entries "hc_query", Query, invoke_query; diff --git a/hdk-rust/src/api/get_links.rs b/hdk-rust/src/api/get_links.rs index 198aea34a3..2ba68a8c63 100644 --- a/hdk-rust/src/api/get_links.rs +++ b/hdk-rust/src/api/get_links.rs @@ -5,7 +5,7 @@ use holochain_core_types::{entry::Entry, link::LinkMatch}; use holochain_persistence_api::{cas::content::Address, hash::HashString}; use holochain_wasm_utils::api_serialization::{ get_entry::{GetEntryOptions, GetEntryResult, GetEntryResultItem, GetEntryResultType}, - get_links::{GetLinksArgs, GetLinksOptions, GetLinksResult}, + get_links::{GetLinksArgs, GetLinksOptions, GetLinksResult,GetLinksResultCount}, }; /// Consumes four values; the address of an entry get get links from (the base), the type of the links @@ -53,6 +53,50 @@ pub fn get_links_with_options( }) } +/// Similar to the get_links_with_options but it allows the user to get the number of links in the dht +/// # Examples +/// ```rust +/// # extern crate hdk; +/// # extern crate holochain_core_types; +/// # extern crate holochain_wasm_utils; +/// # extern crate holochain_json_api; +/// # extern crate holochain_persistence_api; +/// # use holochain_json_api::json::JsonString; +/// # use holochain_persistence_api::cas::content::Address; +/// # use hdk::error::ZomeApiResult; +/// # use holochain_wasm_utils::api_serialization::get_links::{GetLinksResult, GetLinksOptions}; +/// # use holochain_core_types::link::LinkMatch; +/// +/// # fn main() { +/// pub fn handle_posts_by_agent(agent: Address) -> ZomeApiResult { +/// hdk::get_links_count_with_options(&agent, LinkMatch::Exactly("authored_posts"), LinkMatch::Any, GetLinksOptions::default()) +/// } +/// # } +/// ` +pub fn get_links_count_with_options( + base: &Address, + link_type: LinkMatch<&str>, + tag: LinkMatch<&str>, + options: GetLinksOptions, +) -> ZomeApiResult { + let type_re = link_type.to_regex_string()?; + let tag_re = tag.to_regex_string()?; + + Dispatch::GetLinksCount.with_input(GetLinksArgs { + entry_address: base.clone(), + link_type: type_re, + tag: tag_re, + options, + }) +} + +pub fn get_links_count( + base: &Address, + link_type: LinkMatch<&str>, + tag: LinkMatch<&str>, +) -> ZomeApiResult { + get_links_count_with_options(base, link_type, tag, GetLinksOptions::default()) +} /// Helper function for get_links. Returns a vector with the default return results. pub fn get_links( base: &Address, diff --git a/hdk-rust/src/api/mod.rs b/hdk-rust/src/api/mod.rs index c26795d080..1570b4936c 100644 --- a/hdk-rust/src/api/mod.rs +++ b/hdk-rust/src/api/mod.rs @@ -50,7 +50,7 @@ pub use self::{ encrypt::encrypt, entry_address::entry_address, get_entry::{get_entry, get_entry_history, get_entry_initial, get_entry_result}, - get_links::{get_links, get_links_and_load, get_links_result, get_links_with_options}, + get_links::{get_links, get_links_and_load, get_links_result, get_links_with_options,get_links_count_with_options,get_links_count}, keystore::{ keystore_derive_key, keystore_derive_seed, keystore_get_public_key, keystore_list, keystore_new_random, keystore_sign, @@ -176,6 +176,7 @@ def_api_fns! { hc_link_entries, LinkEntries; hc_remove_link, RemoveLink; hc_get_links, GetLinks; + hc_get_links_count,GetLinksCount; hc_sleep, Sleep; hc_keystore_list, KeystoreList; hc_keystore_new_random, KeystoreNewRandom; From b16a4fcf7b02b274d4befbc312a0c5cfed43a830 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Tue, 2 Jul 2019 14:36:36 -0400 Subject: [PATCH 06/48] Added query using crud --- core/src/action.rs | 2 +- core/src/network/actions/get_links_count.rs | 13 +++++++++++-- core/src/network/handler/query.rs | 8 +++++--- core/src/network/query.rs | 2 +- core/src/workflows/get_links_count.rs | 2 +- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/core/src/action.rs b/core/src/action.rs index 3dc5f53df3..cccb39056e 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -157,7 +157,7 @@ pub enum Action { /// Last string is the stringified process unique id of this `hdk::get_links` call. GetLinks(GetLinksKey), GetLinksTimeout(GetLinksKey), - GetLinksCount(GetLinksKey), + GetLinksCount((GetLinksKey,Option)), RespondGetLinks((QueryEntryData, Vec<(Address, CrudStatus)>, String, String)), RespondGetLinksCount((QueryEntryData, usize, String, String)), HandleGetLinksResult((Vec<(Address, CrudStatus)>, GetLinksKey)), diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs index daebb1a2f0..5123313e3e 100644 --- a/core/src/network/actions/get_links_count.rs +++ b/core/src/network/actions/get_links_count.rs @@ -7,10 +7,11 @@ use futures::{ future::Future, task::{LocalWaker, Poll}, }; -use holochain_core_types::{error::HcResult, time::Timeout}; +use holochain_core_types::{error::HcResult, time::Timeout,crud_status::CrudStatus}; use holochain_persistence_api::cas::content::Address; use snowflake::ProcessUniqueId; use std::{pin::Pin, sync::Arc, thread}; +use holochain_wasm_utils::api_serialization::get_links::LinksStatusRequestKind; /// GetLinks Action Creator /// This is the network version of get_links that makes the network module start @@ -21,6 +22,7 @@ pub async fn get_links_count( link_type: String, tag: String, timeout: Timeout, + link_status_request : LinksStatusRequestKind ) -> HcResult { let key = GetLinksKey { base_address: address.clone(), @@ -28,7 +30,14 @@ pub async fn get_links_count( tag: tag.clone(), id: ProcessUniqueId::new().to_string(), }; - let action_wrapper = ActionWrapper::new(Action::GetLinksCount(key.clone())); + + let crud_status = match link_status_request + { + LinksStatusRequestKind::All => None, + LinksStatusRequestKind::Live => Some(CrudStatus::Live), + LinksStatusRequestKind::Deleted => Some(CrudStatus::Deleted) + }; + let action_wrapper = ActionWrapper::new(Action::GetLinksCount((key.clone(),crud_status))); dispatch_action(context.action_channel(), action_wrapper.clone()); let key_inner = key.clone(); diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index fd339e539d..52d96f21c5 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -17,12 +17,13 @@ fn get_links( base: Address, link_type: String, tag: String, + crud_status : Option ) -> Vec<(Address, CrudStatus)> { context .state() .unwrap() .dht() - .get_links(base, link_type, tag) + .get_links(base, link_type, tag,crud_status) .unwrap_or(BTreeSet::new()) .into_iter() .map(|eav_crud| (eav_crud.0.value(), eav_crud.1)) @@ -75,6 +76,7 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc query_data.entry_address.clone(), link_type.clone(), tag.clone(), + None ); ActionWrapper::new(Action::RespondGetLinks(( query_data, @@ -83,9 +85,9 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc tag.clone(), ))) }, - Ok(NetworkQuery::GetLinksCount(link_type,tag)) => + Ok(NetworkQuery::GetLinksCount(link_type,tag,crud)) => { - let links_count = get_links(&context,query_data.entry_address.clone(),link_type.clone(),tag.clone()).len(); + let links_count = get_links(&context,query_data.entry_address.clone(),link_type.clone(),tag.clone(),crud.clone()).len(); ActionWrapper::new(Action::RespondGetLinksCount((query_data,links_count,link_type.clone(),tag.clone()))) }, Ok(NetworkQuery::GetEntry) => { diff --git a/core/src/network/query.rs b/core/src/network/query.rs index 5ae64a628f..eef83202b5 100644 --- a/core/src/network/query.rs +++ b/core/src/network/query.rs @@ -6,7 +6,7 @@ use holochain_persistence_api::cas::content::Address; pub enum NetworkQuery { GetEntry, GetLinks(String, String), - GetLinksCount(String,String) + GetLinksCount(String,String,Option) } #[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] diff --git a/core/src/workflows/get_links_count.rs b/core/src/workflows/get_links_count.rs index 4ca4ca911b..e537e31418 100644 --- a/core/src/workflows/get_links_count.rs +++ b/core/src/workflows/get_links_count.rs @@ -10,7 +10,7 @@ pub async fn get_link_result_count_workflow<'a>( context: Arc, link_args: &'a GetLinksArgs, ) -> Result { - let links_count = await!(get_links_count(context, link_args.entry_address.clone(),link_args.link_type.clone(),link_args.tag.clone(),link_args.options.timeout.clone()))?; + let links_count = await!(get_links_count(context, link_args.entry_address.clone(),link_args.link_type.clone(),link_args.tag.clone(),link_args.options.timeout.clone(),link_args.options.status_request.clone()))?; //get links based on status request, all for everything, deleted for deleted links and live for active links From 4ac5a43f436485863c37e92e7d73029392bb7dc2 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Tue, 2 Jul 2019 16:11:09 -0400 Subject: [PATCH 07/48] Fixed up some misisng code --- app_spec/test/test.js | 10 +-- app_spec/zomes/simple/code/src/lib.rs | 10 +-- core/src/network/reducers/get_links_count.rs | 68 ++++++++++++++++++++ core/src/network/reducers/mod.rs | 3 + hdk-rust/src/api/call.rs | 4 ++ hdk-rust/src/api/get_links.rs | 6 +- hdk-rust/src/macros.rs | 2 + hdk-rust/tests/integration_test.rs | 5 ++ 8 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 core/src/network/reducers/get_links_count.rs diff --git a/app_spec/test/test.js b/app_spec/test/test.js index e80bfe1dcf..c8de2ac170 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -859,6 +859,7 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { await alice.callSync("simple", "create_link", { "base": alice.agentId ,"target": "Holo world" } ); + const alice_result = await alice.callSync("simple", "create_link", { "base": alice.agentId ,"target": "Holo world 2" } ); @@ -876,9 +877,10 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { "status_request":"Live" }) - //make sure all our links are live and they are two of them + + //make sure count equals to 2 t.equal(2,alice_posts_live.Ok.count); - t.equal(2,bob_posts_live.Ok.links.count); + t.equal(2,bob_posts_live.Ok.count); ////delete the holo world post from the links alice created @@ -888,7 +890,7 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { "target" : "Holo world" }); - //get all posts with a deleted status from bob + //get all bob posts const bob_posts_deleted = await bob.call("simple","get_my_links_count", { "base" : alice.agentId, @@ -902,7 +904,7 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { "status_request" : "Deleted" }); - //make sure only 1 is returned and it has a status of deleted + //make sure it is equal to 1 t.equal(1,alice_posts_deleted.Ok.count); t.equal(1,bob_posts_deleted.Ok.count); diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index e73188e432..4e61269e7d 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -26,7 +26,7 @@ use hdk::holochain_json_api::{ }; -use hdk::holochain_wasm_utils::api_serialization::get_links::{GetLinksResult,LinksStatusRequestKind,GetLinksOptions}; +use hdk::holochain_wasm_utils::api_serialization::get_links::{GetLinksResult,LinksStatusRequestKind,GetLinksOptions,GetLinksResultCount}; // see https://developer.holochain.org/api/0.0.18-alpha1/hdk/ for info on using the hdk library @@ -74,13 +74,13 @@ pub fn handle_get_my_links(agent : Address,status_request:Option) ->ZomeApiResult +pub fn handle_get_my_links_count(agent : Address,status_request:Option) ->ZomeApiResult { let options = GetLinksOptions{ status_request : status_request.unwrap_or(LinksStatusRequestKind::All), ..GetLinksOptions::default() }; - hdk::get_links_with_options(&agent, LinkMatch::Exactly("authored_posts"), LinkMatch::Any,options) + hdk::get_links_count_with_options(&agent, LinkMatch::Exactly("authored_posts"), LinkMatch::Any,options) } pub fn handle_test_emit_signal(message: String) -> ZomeApiResult<()> { @@ -161,7 +161,7 @@ define_zome! { } get_my_links_count: { inputs: |base: Address,status_request:Option|, - outputs: |result: ZomeApiResult|, + outputs: |result: ZomeApiResult|, handler: handle_get_my_links_count } encrypt :{ @@ -182,7 +182,7 @@ define_zome! { ] traits: { - hc_public [create_link, delete_link, get_my_links, test_emit_signal] + hc_public [create_link, delete_link, get_my_links, test_emit_signal,get_my_links_count] } } diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs new file mode 100644 index 0000000000..362fa73c29 --- /dev/null +++ b/core/src/network/reducers/get_links_count.rs @@ -0,0 +1,68 @@ +use crate::{ + action::{ActionWrapper, GetLinksKey}, + network::{query::NetworkQuery, reducers::send, state::NetworkState}, + state::State, +}; + +use holochain_core_types::error::HolochainError; +use holochain_json_api::json::JsonString; +use holochain_net::connection::json_protocol::{JsonProtocol, QueryEntryData}; +use holochain_persistence_api::hash::HashString; +use holochain_core_types::crud_status::CrudStatus; + +fn reduce_get_links_inner( + network_state: &mut NetworkState, + key: &GetLinksKey, + crud_status : Option +) -> Result<(), HolochainError> { + network_state.initialized()?; + let query_json: JsonString = + NetworkQuery::GetLinksCount(key.link_type.clone(), key.tag.clone(),crud_status).into(); + send( + network_state, + JsonProtocol::QueryEntry(QueryEntryData { + requester_agent_id: network_state.agent_id.clone().unwrap().into(), + request_id: key.id.clone(), + dna_address: network_state.dna_address.clone().unwrap(), + entry_address: HashString::from(key.base_address.clone()), + query: query_json.to_string().into_bytes(), + }), + ) +} + +pub fn reduce_get_links_count( + network_state: &mut NetworkState, + _root_state: &State, + action_wrapper: &ActionWrapper, +) { + let action = action_wrapper.action(); + let (key,crud) = unwrap_to!(action => crate::action::Action::GetLinksCount); + + let result = match reduce_get_links_inner(network_state, &key,crud.clone()) { + Ok(()) => None, + Err(err) => Some(Err(err)), + }; + + network_state.get_links_results.insert(key.clone(), result); +} + +pub fn reduce_get_links_timeout( + network_state: &mut NetworkState, + _root_state: &State, + action_wrapper: &ActionWrapper, +) { + let action = action_wrapper.action(); + let key = unwrap_to!(action => crate::action::Action::GetLinksTimeout); + + if network_state.get_links_results.get(key).is_none() { + return; + } + + if network_state.get_links_results.get(key).unwrap().is_none() { + network_state + .get_links_results + .insert(key.clone(), Some(Err(HolochainError::Timeout))); + } +} + + diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index d702e73713..ecdb220357 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -1,5 +1,6 @@ pub mod get_entry; pub mod get_links; +pub mod get_links_count; pub mod get_validation_package; pub mod handle_custom_send_response; pub mod handle_get_links_result; @@ -22,6 +23,7 @@ use crate::{ reducers::{ get_entry::{reduce_get_entry, reduce_get_entry_timeout}, get_links::{reduce_get_links, reduce_get_links_timeout}, + get_links_count::reduce_get_links_count, get_validation_package::reduce_get_validation_package, handle_custom_send_response::reduce_handle_custom_send_response, handle_get_links_result::reduce_handle_get_links_result, @@ -57,6 +59,7 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::GetEntry(_) => Some(reduce_get_entry), Action::GetEntryTimeout(_) => Some(reduce_get_entry_timeout), Action::GetLinks(_) => Some(reduce_get_links), + Action::GetLinksCount(_) =>Some(reduce_get_links_count), Action::GetLinksTimeout(_) => Some(reduce_get_links_timeout), Action::GetValidationPackage(_) => Some(reduce_get_validation_package), Action::HandleCustomSendResponse(_) => Some(reduce_handle_custom_send_response), diff --git a/hdk-rust/src/api/call.rs b/hdk-rust/src/api/call.rs index 4220375d44..a09a928fca 100644 --- a/hdk-rust/src/api/call.rs +++ b/hdk-rust/src/api/call.rs @@ -59,6 +59,8 @@ use holochain_wasm_utils::api_serialization::ZomeFnCallArgs; /// # #[no_mangle] /// # pub fn hc_get_links(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } /// # #[no_mangle] +/// # pub fn hc_get_links_count(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } +/// # #[no_mangle] /// # pub fn hc_link_entries(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } /// # #[no_mangle] /// # pub fn hc_remove_link(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } @@ -166,6 +168,8 @@ use holochain_wasm_utils::api_serialization::ZomeFnCallArgs; /// # #[no_mangle] /// # pub fn hc_get_links(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } /// # #[no_mangle] +/// # pub fn hc_get_links_count(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } +/// # #[no_mangle] /// # pub fn hc_link_entries(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } /// # #[no_mangle] /// # pub fn hc_remove_link(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } diff --git a/hdk-rust/src/api/get_links.rs b/hdk-rust/src/api/get_links.rs index 2ba68a8c63..a33848aa3e 100644 --- a/hdk-rust/src/api/get_links.rs +++ b/hdk-rust/src/api/get_links.rs @@ -64,15 +64,15 @@ pub fn get_links_with_options( /// # use holochain_json_api::json::JsonString; /// # use holochain_persistence_api::cas::content::Address; /// # use hdk::error::ZomeApiResult; -/// # use holochain_wasm_utils::api_serialization::get_links::{GetLinksResult, GetLinksOptions}; +/// # use holochain_wasm_utils::api_serialization::get_links::{GetLinksResultCount, GetLinksOptions}; /// # use holochain_core_types::link::LinkMatch; /// /// # fn main() { -/// pub fn handle_posts_by_agent(agent: Address) -> ZomeApiResult { +/// pub fn handle_posts_count_by_agent(agent: Address) -> ZomeApiResult { /// hdk::get_links_count_with_options(&agent, LinkMatch::Exactly("authored_posts"), LinkMatch::Any, GetLinksOptions::default()) /// } /// # } -/// ` +/// ``` pub fn get_links_count_with_options( base: &Address, link_type: LinkMatch<&str>, diff --git a/hdk-rust/src/macros.rs b/hdk-rust/src/macros.rs index 60e33dab85..24eec6fb5e 100644 --- a/hdk-rust/src/macros.rs +++ b/hdk-rust/src/macros.rs @@ -112,6 +112,8 @@ macro_rules! load_string { /// # #[no_mangle] /// # pub fn hc_get_links(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } /// # #[no_mangle] +/// # pub fn hc_get_links_count(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } +/// # #[no_mangle] /// # pub fn hc_link_entries(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } /// # #[no_mangle] /// # pub fn hc_remove_link(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } diff --git a/hdk-rust/tests/integration_test.rs b/hdk-rust/tests/integration_test.rs index 746b8eef79..55e3a534c1 100755 --- a/hdk-rust/tests/integration_test.rs +++ b/hdk-rust/tests/integration_test.rs @@ -148,6 +148,11 @@ pub fn hc_get_links(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } +#[no_mangle] +pub fn hc_get_links_count(_: RibosomeEncodingBits) -> RibosomeEncodingBits { + RibosomeEncodedValue::Success.into() +} + #[no_mangle] pub fn hc_start_bundle(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() From 29bcc9427be1e6daeba749cac92c1138cc23f0c4 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Tue, 2 Jul 2019 16:11:22 -0400 Subject: [PATCH 08/48] cargo fmt --- core/src/action.rs | 2 +- core/src/dht/dht_store.rs | 4 +-- core/src/network/actions/get_links_count.rs | 13 ++++---- core/src/network/actions/mod.rs | 2 +- core/src/network/handler/query.rs | 31 +++++++++++++------ core/src/network/query.rs | 4 +-- core/src/network/reducers/get_links_count.rs | 13 +++----- core/src/network/reducers/mod.rs | 4 +-- .../reducers/respond_get_links_count.rs | 1 - core/src/network/state.rs | 4 +-- core/src/nucleus/ribosome/api/get_links.rs | 3 -- .../nucleus/ribosome/api/get_links_count.rs | 5 --- core/src/workflows/get_links_count.rs | 20 +++++++----- hdk-rust/src/api/get_links.rs | 2 +- hdk-rust/src/api/mod.rs | 5 ++- wasm_utils/src/api_serialization/get_links.rs | 7 ++--- 16 files changed, 61 insertions(+), 59 deletions(-) diff --git a/core/src/action.rs b/core/src/action.rs index cccb39056e..334192fab3 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -157,7 +157,7 @@ pub enum Action { /// Last string is the stringified process unique id of this `hdk::get_links` call. GetLinks(GetLinksKey), GetLinksTimeout(GetLinksKey), - GetLinksCount((GetLinksKey,Option)), + GetLinksCount((GetLinksKey, Option)), RespondGetLinks((QueryEntryData, Vec<(Address, CrudStatus)>, String, String)), RespondGetLinksCount((QueryEntryData, usize, String, String)), HandleGetLinksResult((Vec<(Address, CrudStatus)>, GetLinksKey)), diff --git a/core/src/dht/dht_store.rs b/core/src/dht/dht_store.rs index 9a7bd4fc26..816d2acaa2 100644 --- a/core/src/dht/dht_store.rs +++ b/core/src/dht/dht_store.rs @@ -93,7 +93,7 @@ impl DhtStore { address: Address, link_type: String, tag: String, - crud_filter : Option + crud_filter: Option, ) -> Result, HolochainError> { let get_links_query = create_get_links_eavi_query(address, link_type, tag)?; let filtered = self.meta_storage.read()?.fetch_eavi(&get_links_query)?; @@ -103,7 +103,7 @@ impl DhtStore { Attribute::LinkTag(_, _) => (s, CrudStatus::Live), _ => (s, CrudStatus::Deleted), }) - .filter(|link_crud| crud_filter.map(|crud| crud==link_crud.1).unwrap_or(true)) + .filter(|link_crud| crud_filter.map(|crud| crud == link_crud.1).unwrap_or(true)) .collect()) } diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs index 5123313e3e..45f3ab76b8 100644 --- a/core/src/network/actions/get_links_count.rs +++ b/core/src/network/actions/get_links_count.rs @@ -7,11 +7,11 @@ use futures::{ future::Future, task::{LocalWaker, Poll}, }; -use holochain_core_types::{error::HcResult, time::Timeout,crud_status::CrudStatus}; +use holochain_core_types::{crud_status::CrudStatus, error::HcResult, time::Timeout}; use holochain_persistence_api::cas::content::Address; +use holochain_wasm_utils::api_serialization::get_links::LinksStatusRequestKind; use snowflake::ProcessUniqueId; use std::{pin::Pin, sync::Arc, thread}; -use holochain_wasm_utils::api_serialization::get_links::LinksStatusRequestKind; /// GetLinks Action Creator /// This is the network version of get_links that makes the network module start @@ -22,7 +22,7 @@ pub async fn get_links_count( link_type: String, tag: String, timeout: Timeout, - link_status_request : LinksStatusRequestKind + link_status_request: LinksStatusRequestKind, ) -> HcResult { let key = GetLinksKey { base_address: address.clone(), @@ -31,13 +31,12 @@ pub async fn get_links_count( id: ProcessUniqueId::new().to_string(), }; - let crud_status = match link_status_request - { + let crud_status = match link_status_request { LinksStatusRequestKind::All => None, LinksStatusRequestKind::Live => Some(CrudStatus::Live), - LinksStatusRequestKind::Deleted => Some(CrudStatus::Deleted) + LinksStatusRequestKind::Deleted => Some(CrudStatus::Deleted), }; - let action_wrapper = ActionWrapper::new(Action::GetLinksCount((key.clone(),crud_status))); + let action_wrapper = ActionWrapper::new(Action::GetLinksCount((key.clone(), crud_status))); dispatch_action(context.action_channel(), action_wrapper.clone()); let key_inner = key.clone(); diff --git a/core/src/network/actions/mod.rs b/core/src/network/actions/mod.rs index 0fe1fc607c..e3ed95ad8f 100644 --- a/core/src/network/actions/mod.rs +++ b/core/src/network/actions/mod.rs @@ -15,5 +15,5 @@ pub enum ActionResponse { RespondGet(HcResult<()>), RespondFetch(HcResult<()>), RespondGetLinks(HcResult<()>), - RespondGetLinksCount(HcResult<()>) + RespondGetLinksCount(HcResult<()>), } diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index 52d96f21c5..a6f3e7a412 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -17,13 +17,13 @@ fn get_links( base: Address, link_type: String, tag: String, - crud_status : Option + crud_status: Option, ) -> Vec<(Address, CrudStatus)> { context .state() .unwrap() .dht() - .get_links(base, link_type, tag,crud_status) + .get_links(base, link_type, tag, crud_status) .unwrap_or(BTreeSet::new()) .into_iter() .map(|eav_crud| (eav_crud.0.value(), eav_crud.1)) @@ -76,7 +76,7 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc query_data.entry_address.clone(), link_type.clone(), tag.clone(), - None + None, ); ActionWrapper::new(Action::RespondGetLinks(( query_data, @@ -84,12 +84,23 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc link_type.clone(), tag.clone(), ))) - }, - Ok(NetworkQuery::GetLinksCount(link_type,tag,crud)) => - { - let links_count = get_links(&context,query_data.entry_address.clone(),link_type.clone(),tag.clone(),crud.clone()).len(); - ActionWrapper::new(Action::RespondGetLinksCount((query_data,links_count,link_type.clone(),tag.clone()))) - }, + } + Ok(NetworkQuery::GetLinksCount(link_type, tag, crud)) => { + let links_count = get_links( + &context, + query_data.entry_address.clone(), + link_type.clone(), + tag.clone(), + crud.clone(), + ) + .len(); + ActionWrapper::new(Action::RespondGetLinksCount(( + query_data, + links_count, + link_type.clone(), + tag.clone(), + ))) + } Ok(NetworkQuery::GetEntry) => { let maybe_entry = get_entry(&context, query_data.entry_address.clone()); ActionWrapper::new(Action::RespondGet((query_data, maybe_entry))) @@ -130,7 +141,7 @@ pub fn handle_query_entry_result(query_result_data: QueryEntryResultData, contex id: query_result_data.request_id.clone(), }, ))) - }, + } Ok(NetworkQueryResult::LinksCount(links_count, link_type, tag)) => { ActionWrapper::new(Action::HandleGetLinksResultCount(( links_count, diff --git a/core/src/network/query.rs b/core/src/network/query.rs index eef83202b5..cc4545c4b8 100644 --- a/core/src/network/query.rs +++ b/core/src/network/query.rs @@ -6,12 +6,12 @@ use holochain_persistence_api::cas::content::Address; pub enum NetworkQuery { GetEntry, GetLinks(String, String), - GetLinksCount(String,String,Option) + GetLinksCount(String, String, Option), } #[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] pub enum NetworkQueryResult { Entry(Option), Links(Vec<(Address, CrudStatus)>, String, String), - LinksCount(usize, String, String) + LinksCount(usize, String, String), } diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs index 362fa73c29..120d12823b 100644 --- a/core/src/network/reducers/get_links_count.rs +++ b/core/src/network/reducers/get_links_count.rs @@ -4,20 +4,19 @@ use crate::{ state::State, }; -use holochain_core_types::error::HolochainError; +use holochain_core_types::{crud_status::CrudStatus, error::HolochainError}; use holochain_json_api::json::JsonString; use holochain_net::connection::json_protocol::{JsonProtocol, QueryEntryData}; use holochain_persistence_api::hash::HashString; -use holochain_core_types::crud_status::CrudStatus; fn reduce_get_links_inner( network_state: &mut NetworkState, key: &GetLinksKey, - crud_status : Option + crud_status: Option, ) -> Result<(), HolochainError> { network_state.initialized()?; let query_json: JsonString = - NetworkQuery::GetLinksCount(key.link_type.clone(), key.tag.clone(),crud_status).into(); + NetworkQuery::GetLinksCount(key.link_type.clone(), key.tag.clone(), crud_status).into(); send( network_state, JsonProtocol::QueryEntry(QueryEntryData { @@ -36,9 +35,9 @@ pub fn reduce_get_links_count( action_wrapper: &ActionWrapper, ) { let action = action_wrapper.action(); - let (key,crud) = unwrap_to!(action => crate::action::Action::GetLinksCount); + let (key, crud) = unwrap_to!(action => crate::action::Action::GetLinksCount); - let result = match reduce_get_links_inner(network_state, &key,crud.clone()) { + let result = match reduce_get_links_inner(network_state, &key, crud.clone()) { Ok(()) => None, Err(err) => Some(Err(err)), }; @@ -64,5 +63,3 @@ pub fn reduce_get_links_timeout( .insert(key.clone(), Some(Err(HolochainError::Timeout))); } } - - diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index ecdb220357..f75ed611a1 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -5,7 +5,6 @@ pub mod get_validation_package; pub mod handle_custom_send_response; pub mod handle_get_links_result; pub mod handle_get_links_result_count; -pub mod respond_get_links_count; pub mod handle_get_result; pub mod handle_get_validation_package; pub mod init; @@ -14,6 +13,7 @@ pub mod resolve_direct_connection; pub mod respond_fetch; pub mod respond_get; pub mod respond_get_links; +pub mod respond_get_links_count; pub mod send_direct_message; use crate::{ @@ -59,7 +59,7 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::GetEntry(_) => Some(reduce_get_entry), Action::GetEntryTimeout(_) => Some(reduce_get_entry_timeout), Action::GetLinks(_) => Some(reduce_get_links), - Action::GetLinksCount(_) =>Some(reduce_get_links_count), + Action::GetLinksCount(_) => Some(reduce_get_links_count), Action::GetLinksTimeout(_) => Some(reduce_get_links_timeout), Action::GetValidationPackage(_) => Some(reduce_get_validation_package), Action::HandleCustomSendResponse(_) => Some(reduce_handle_custom_send_response), diff --git a/core/src/network/reducers/respond_get_links_count.rs b/core/src/network/reducers/respond_get_links_count.rs index fab493ad08..df0664ac1f 100644 --- a/core/src/network/reducers/respond_get_links_count.rs +++ b/core/src/network/reducers/respond_get_links_count.rs @@ -11,7 +11,6 @@ use holochain_net::connection::json_protocol::{ JsonProtocol, QueryEntryData, QueryEntryResultData, }; - /// Send back to network a HandleQueryEntryResult, no matter what. /// Will return an empty content field if it actually doesn't have the data. fn reduce_respond_get_links_count_inner( diff --git a/core/src/network/state.rs b/core/src/network/state.rs index 041576b111..2fb4f08548 100644 --- a/core/src/network/state.rs +++ b/core/src/network/state.rs @@ -61,7 +61,7 @@ pub struct NetworkState { /// None means that we are still waiting for a result from the network. pub get_links_results: HashMap, - pub get_links_results_count : HashMap, + pub get_links_results_count: HashMap, /// Here we store the results of get validation package processes. /// None means that we are still waiting for a result from the network. @@ -92,7 +92,7 @@ impl NetworkState { get_entry_with_meta_results: HashMap::new(), get_links_results: HashMap::new(), - get_links_results_count : HashMap::new(), + get_links_results_count: HashMap::new(), get_validation_package_results: HashMap::new(), direct_message_connections: HashMap::new(), custom_direct_message_replys: HashMap::new(), diff --git a/core/src/nucleus/ribosome/api/get_links.rs b/core/src/nucleus/ribosome/api/get_links.rs index b23d6c7336..85f00666e7 100644 --- a/core/src/nucleus/ribosome/api/get_links.rs +++ b/core/src/nucleus/ribosome/api/get_links.rs @@ -31,14 +31,11 @@ pub fn invoke_get_links(runtime: &mut Runtime, args: &RuntimeArgs) -> ZomeApiRes } }; - let result = context.block_on(get_link_result_workflow(&context, &input)); runtime.store_result(result) } - - #[cfg(test)] pub mod tests { use std::sync::Arc; diff --git a/core/src/nucleus/ribosome/api/get_links_count.rs b/core/src/nucleus/ribosome/api/get_links_count.rs index 5aad7d74a9..8977e00379 100644 --- a/core/src/nucleus/ribosome/api/get_links_count.rs +++ b/core/src/nucleus/ribosome/api/get_links_count.rs @@ -6,8 +6,6 @@ use holochain_wasm_utils::api_serialization::get_links::GetLinksArgs; use std::convert::TryFrom; use wasmi::{RuntimeArgs, RuntimeValue}; - - pub fn invoke_get_links_count(runtime: &mut Runtime, args: &RuntimeArgs) -> ZomeApiResult { let context = runtime.context()?; // deserialize args @@ -29,10 +27,7 @@ pub fn invoke_get_links_count(runtime: &mut Runtime, args: &RuntimeArgs) -> Zome } }; - let result = context.block_on(get_link_result_count_workflow(context.clone(), &input)); runtime.store_result(result) } - - diff --git a/core/src/workflows/get_links_count.rs b/core/src/workflows/get_links_count.rs index e537e31418..52e140564d 100644 --- a/core/src/workflows/get_links_count.rs +++ b/core/src/workflows/get_links_count.rs @@ -1,18 +1,22 @@ -use crate::{ - context::Context, network::actions::get_links_count::get_links_count -}; +use crate::{context::Context, network::actions::get_links_count::get_links_count}; use holochain_core_types::error::HolochainError; -use holochain_wasm_utils::api_serialization::get_links::{GetLinksArgs,GetLinksResultCount}; +use holochain_wasm_utils::api_serialization::get_links::{GetLinksArgs, GetLinksResultCount}; use std::sync::Arc; pub async fn get_link_result_count_workflow<'a>( context: Arc, link_args: &'a GetLinksArgs, ) -> Result { - let links_count = await!(get_links_count(context, link_args.entry_address.clone(),link_args.link_type.clone(),link_args.tag.clone(),link_args.options.timeout.clone(),link_args.options.status_request.clone()))?; + let links_count = await!(get_links_count( + context, + link_args.entry_address.clone(), + link_args.link_type.clone(), + link_args.tag.clone(), + link_args.options.timeout.clone(), + link_args.options.status_request.clone() + ))?; //get links based on status request, all for everything, deleted for deleted links and live for active links - - Ok(GetLinksResultCount{count:links_count}) -} \ No newline at end of file + Ok(GetLinksResultCount { count: links_count }) +} diff --git a/hdk-rust/src/api/get_links.rs b/hdk-rust/src/api/get_links.rs index a33848aa3e..a723e6a952 100644 --- a/hdk-rust/src/api/get_links.rs +++ b/hdk-rust/src/api/get_links.rs @@ -5,7 +5,7 @@ use holochain_core_types::{entry::Entry, link::LinkMatch}; use holochain_persistence_api::{cas::content::Address, hash::HashString}; use holochain_wasm_utils::api_serialization::{ get_entry::{GetEntryOptions, GetEntryResult, GetEntryResultItem, GetEntryResultType}, - get_links::{GetLinksArgs, GetLinksOptions, GetLinksResult,GetLinksResultCount}, + get_links::{GetLinksArgs, GetLinksOptions, GetLinksResult, GetLinksResultCount}, }; /// Consumes four values; the address of an entry get get links from (the base), the type of the links diff --git a/hdk-rust/src/api/mod.rs b/hdk-rust/src/api/mod.rs index 1570b4936c..dc896171ac 100644 --- a/hdk-rust/src/api/mod.rs +++ b/hdk-rust/src/api/mod.rs @@ -50,7 +50,10 @@ pub use self::{ encrypt::encrypt, entry_address::entry_address, get_entry::{get_entry, get_entry_history, get_entry_initial, get_entry_result}, - get_links::{get_links, get_links_and_load, get_links_result, get_links_with_options,get_links_count_with_options,get_links_count}, + get_links::{ + get_links, get_links_and_load, get_links_count, get_links_count_with_options, + get_links_result, get_links_with_options, + }, keystore::{ keystore_derive_key, keystore_derive_seed, keystore_get_public_key, keystore_list, keystore_new_random, keystore_sign, diff --git a/wasm_utils/src/api_serialization/get_links.rs b/wasm_utils/src/api_serialization/get_links.rs index 334ab6b300..cd71ea85eb 100644 --- a/wasm_utils/src/api_serialization/get_links.rs +++ b/wasm_utils/src/api_serialization/get_links.rs @@ -7,7 +7,7 @@ pub struct GetLinksArgs { pub entry_address: Address, pub link_type: String, pub tag: String, - pub options: GetLinksOptions + pub options: GetLinksOptions, } #[derive(Deserialize, Debug, Serialize, DefaultJson, Clone, PartialEq, Eq, Hash)] @@ -38,9 +38,6 @@ impl Default for GetLinksOptions { } } - - - #[derive(Deserialize, Serialize, Debug, DefaultJson)] pub struct LinksResult { pub address: Address, @@ -56,7 +53,7 @@ pub struct GetLinksResult { #[derive(Deserialize, Serialize, Debug, DefaultJson)] pub struct GetLinksResultCount { - pub count: usize + pub count: usize, } impl GetLinksResult { From 550e21e91fd4b53ef7a51cc878a967ad9ec83ba6 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Tue, 2 Jul 2019 16:14:38 -0400 Subject: [PATCH 09/48] update proc macro --- app_spec_proc_macro/zomes/simple/code/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app_spec_proc_macro/zomes/simple/code/src/lib.rs b/app_spec_proc_macro/zomes/simple/code/src/lib.rs index 2758bca56d..071a9b6554 100644 --- a/app_spec_proc_macro/zomes/simple/code/src/lib.rs +++ b/app_spec_proc_macro/zomes/simple/code/src/lib.rs @@ -27,7 +27,7 @@ use hdk::{ json::JsonString, error::JsonError }, - holochain_wasm_utils::api_serialization::get_links::{GetLinksResult,LinksStatusRequestKind,GetLinksOptions} + holochain_wasm_utils::api_serialization::get_links::{GetLinksResult,LinksStatusRequestKind,GetLinksOptions,GetLinksResultCount} }; @@ -125,7 +125,7 @@ pub mod simple { } #[zome_fn("hc_public")] - pub fn get_my_links_count(base: Address,status_request : Option) -> ZomeApiResult + pub fn get_my_links_count(base: Address,status_request : Option) -> ZomeApiResult { let options = GetLinksOptions{ status_request : status_request.unwrap_or(LinksStatusRequestKind::All), From 2687c7a541446b3a0788bdb7a4426072cc2291f2 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Tue, 2 Jul 2019 16:57:25 -0400 Subject: [PATCH 10/48] Update lib.rs --- app_spec_proc_macro/zomes/simple/code/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec_proc_macro/zomes/simple/code/src/lib.rs b/app_spec_proc_macro/zomes/simple/code/src/lib.rs index 2821927ea3..def63a3941 100644 --- a/app_spec_proc_macro/zomes/simple/code/src/lib.rs +++ b/app_spec_proc_macro/zomes/simple/code/src/lib.rs @@ -131,7 +131,7 @@ pub mod simple { status_request : status_request.unwrap_or(LinksStatusRequestKind::All), ..GetLinksOptions::default() }; - hdk::get_links_with_count_options(&base, LinkMatch::Exactly("authored_posts"), LinkMatch::Any,options) + hdk::get_links_count_with_options(&base, LinkMatch::Exactly("authored_posts"), LinkMatch::Any,options) } #[zome_fn("hc_public")] From 656afcbf6702a0efc497a62c43b89dcd6b05ff82 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 06:25:36 -0400 Subject: [PATCH 11/48] GetLinksCount enum --- core/src/network/actions/get_links_count.rs | 2 ++ .../nucleus/ribosome/api/get_links_count.rs | 5 ++-- core/src/workflows/get_links_count.rs | 28 ++++++++++++------- hdk-rust/src/api/get_links.rs | 18 ++++++++++-- wasm_utils/src/api_serialization/get_links.rs | 7 +++++ 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs index 45f3ab76b8..6511dcb2e6 100644 --- a/core/src/network/actions/get_links_count.rs +++ b/core/src/network/actions/get_links_count.rs @@ -53,6 +53,8 @@ pub async fn get_links_count( }) } + + /// GetLinksFuture resolves to a HcResult>. /// Tracks the state of the network module pub struct GetLinksCountFuture { diff --git a/core/src/nucleus/ribosome/api/get_links_count.rs b/core/src/nucleus/ribosome/api/get_links_count.rs index 8977e00379..ca412dcd6b 100644 --- a/core/src/nucleus/ribosome/api/get_links_count.rs +++ b/core/src/nucleus/ribosome/api/get_links_count.rs @@ -2,7 +2,7 @@ use crate::{ nucleus::ribosome::{api::ZomeApiResult, Runtime}, workflows::get_links_count::get_link_result_count_workflow, }; -use holochain_wasm_utils::api_serialization::get_links::GetLinksArgs; +use holochain_wasm_utils::api_serialization::get_links::GetLinksBy; use std::convert::TryFrom; use wasmi::{RuntimeArgs, RuntimeValue}; @@ -10,7 +10,8 @@ pub fn invoke_get_links_count(runtime: &mut Runtime, args: &RuntimeArgs) -> Zome let context = runtime.context()?; // deserialize args let args_str = runtime.load_json_string_from_args(&args); - let input = match GetLinksArgs::try_from(args_str.clone()) { + + let input = match GetLinksBy::try_from(args_str.clone()) { Ok(input) => { context.log(format!( "log/get_links: invoke_get_links called with {:?}", diff --git a/core/src/workflows/get_links_count.rs b/core/src/workflows/get_links_count.rs index 52e140564d..98c09221c9 100644 --- a/core/src/workflows/get_links_count.rs +++ b/core/src/workflows/get_links_count.rs @@ -1,21 +1,29 @@ use crate::{context::Context, network::actions::get_links_count::get_links_count}; use holochain_core_types::error::HolochainError; -use holochain_wasm_utils::api_serialization::get_links::{GetLinksArgs, GetLinksResultCount}; +use holochain_wasm_utils::api_serialization::get_links::{ GetLinksResultCount,GetLinksBy}; use std::sync::Arc; pub async fn get_link_result_count_workflow<'a>( context: Arc, - link_args: &'a GetLinksArgs, + link_args: &'a GetLinksBy, ) -> Result { - let links_count = await!(get_links_count( - context, - link_args.entry_address.clone(), - link_args.link_type.clone(), - link_args.tag.clone(), - link_args.options.timeout.clone(), - link_args.options.status_request.clone() - ))?; + let links_count = match link_args + { + GetLinksBy::GetLinksArgs(link_args)=> + { + await!(get_links_count(context, + link_args.entry_address.clone(), + link_args.link_type.clone(), + link_args.tag.clone(), + link_args.options.timeout.clone(), + link_args.options.status_request.clone()))? + }, + GetLinksBy::Tag(_,_) => + { + unimplemented!("Not yet") + } + }; //get links based on status request, all for everything, deleted for deleted links and live for active links Ok(GetLinksResultCount { count: links_count }) diff --git a/hdk-rust/src/api/get_links.rs b/hdk-rust/src/api/get_links.rs index a723e6a952..93a352133a 100644 --- a/hdk-rust/src/api/get_links.rs +++ b/hdk-rust/src/api/get_links.rs @@ -5,7 +5,7 @@ use holochain_core_types::{entry::Entry, link::LinkMatch}; use holochain_persistence_api::{cas::content::Address, hash::HashString}; use holochain_wasm_utils::api_serialization::{ get_entry::{GetEntryOptions, GetEntryResult, GetEntryResultItem, GetEntryResultType}, - get_links::{GetLinksArgs, GetLinksOptions, GetLinksResult, GetLinksResultCount}, + get_links::{GetLinksArgs, GetLinksOptions, GetLinksResult, GetLinksResultCount,GetLinksBy}, }; /// Consumes four values; the address of an entry get get links from (the base), the type of the links @@ -82,12 +82,13 @@ pub fn get_links_count_with_options( let type_re = link_type.to_regex_string()?; let tag_re = tag.to_regex_string()?; - Dispatch::GetLinksCount.with_input(GetLinksArgs { + let get_links_args = GetLinksBy::GetLinksArgs(GetLinksArgs { entry_address: base.clone(), link_type: type_re, tag: tag_re, options, - }) + }); + Dispatch::GetLinksCount.with_input(get_links_args) } pub fn get_links_count( @@ -97,6 +98,17 @@ pub fn get_links_count( ) -> ZomeApiResult { get_links_count_with_options(base, link_type, tag, GetLinksOptions::default()) } + +pub fn get_links_by_tag( + tag: LinkMatch<&str>, + options : GetLinksOptions +) -> ZomeApiResult { + let tag_re = tag.to_regex_string()?; + let get_links_args = GetLinksBy::Tag(tag_re,options); + Dispatch::GetLinksCount.with_input(get_links_args) +} + + /// Helper function for get_links. Returns a vector with the default return results. pub fn get_links( base: &Address, diff --git a/wasm_utils/src/api_serialization/get_links.rs b/wasm_utils/src/api_serialization/get_links.rs index cd71ea85eb..94cb90f170 100644 --- a/wasm_utils/src/api_serialization/get_links.rs +++ b/wasm_utils/src/api_serialization/get_links.rs @@ -51,6 +51,13 @@ pub struct GetLinksResult { links: Vec, } +#[derive(Deserialize, Debug, Serialize, DefaultJson, Clone, PartialEq, Hash, Eq)] +pub enum GetLinksBy +{ + GetLinksArgs(GetLinksArgs), + Tag(String,GetLinksOptions) +} + #[derive(Deserialize, Serialize, Debug, DefaultJson)] pub struct GetLinksResultCount { pub count: usize, From e24601e1eec2cde42baec9c7df74f9cdfd32e87b Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 07:11:31 -0400 Subject: [PATCH 12/48] Made some changes for the tag --- core/src/action.rs | 13 +++++ core/src/dht/dht_store.rs | 41 +++++++++++++ core/src/network/actions/get_links_count.rs | 61 +++++++++++++++++++- core/src/network/handler/query.rs | 30 ++++++++++ core/src/network/query.rs | 2 + core/src/network/reducers/get_links_count.rs | 38 +++++++++++- core/src/network/reducers/mod.rs | 3 +- core/src/network/state.rs | 5 +- 8 files changed, 189 insertions(+), 4 deletions(-) diff --git a/core/src/action.rs b/core/src/action.rs index 334192fab3..4ba1f2395d 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -158,6 +158,7 @@ pub enum Action { GetLinks(GetLinksKey), GetLinksTimeout(GetLinksKey), GetLinksCount((GetLinksKey, Option)), + GetLinksCountByTag((GetLinksKeyByTag,Option)), RespondGetLinks((QueryEntryData, Vec<(Address, CrudStatus)>, String, String)), RespondGetLinksCount((QueryEntryData, usize, String, String)), HandleGetLinksResult((Vec<(Address, CrudStatus)>, GetLinksKey)), @@ -257,6 +258,18 @@ pub struct GetLinksKey { pub id: String, } +/// The unique key that represents a GetLinksCountByTag request, used to associate the eventual +/// response with this GetLinks request +#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)] +pub struct GetLinksKeyByTag { + + /// The link tag, None means get all the tags for a given type + pub tag: String, + + /// A unique ID that is used to pair the eventual result to this request + pub id: String, +} + /// The unique key that represents a Get request, used to associate the eventual /// response with this Get request #[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)] diff --git a/core/src/dht/dht_store.rs b/core/src/dht/dht_store.rs index 816d2acaa2..9372114017 100644 --- a/core/src/dht/dht_store.rs +++ b/core/src/dht/dht_store.rs @@ -71,6 +71,30 @@ pub fn create_get_links_eavi_query<'a>( )) } +pub fn create_get_links_by_tag_eavi_query<'a>(tag : String) -> Result, HolochainError> +{ + let tag_regex =Regex::new(&tag).map_err(|_| HolochainError::from("Invalid regex passed for tag"))?; + Ok(EaviQuery::new( + None.into(), + EavFilter::predicate(move |attr: Attribute| match attr.clone() { + Attribute::LinkTag(_, query_tag) + | Attribute::RemovedLink(_, query_tag) => { + tag_regex.is_match(&query_tag) + } + _ => false, + }), + None.into(), + IndexFilter::LatestByAttribute, + Some(EavFilter::predicate(move |attr: Attribute| match attr.clone() { + Attribute::RemovedLink(_, query_tag) => { + tag_regex.is_match(&query_tag) + } + _ => false, + } + ))), + ) +} + impl DhtStore { // LifeCycle // ========= @@ -107,6 +131,23 @@ impl DhtStore { .collect()) } + pub fn get_links_by_tag( + &self, + tag: String, + crud_filter: Option, + ) -> Result, HolochainError> { + let get_links_query = create_get_links_by_tag_eavi_query(tag)?; + let filtered = self.meta_storage.read()?.fetch_eavi(&get_links_query)?; + Ok(filtered + .into_iter() + .map(|s| match s.attribute() { + Attribute::LinkTag(_, _) => (s, CrudStatus::Live), + _ => (s, CrudStatus::Deleted), + }) + .filter(|link_crud| crud_filter.map(|crud| crud == link_crud.1).unwrap_or(true)) + .collect()) + } + pub fn get_all_metas( &self, address: &Address, diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs index 6511dcb2e6..6218c94fcb 100644 --- a/core/src/network/actions/get_links_count.rs +++ b/core/src/network/actions/get_links_count.rs @@ -1,5 +1,5 @@ use crate::{ - action::{Action, ActionWrapper, GetLinksKey}, + action::{Action, ActionWrapper, GetLinksKey,GetLinksKeyByTag}, context::Context, instance::dispatch_action, }; @@ -54,6 +54,38 @@ pub async fn get_links_count( } +pub async fn get_links_count_by_tag( + context: Arc, + tag: String, + _timeout: Timeout, + link_status_request: LinksStatusRequestKind, +) -> HcResult { + let key = GetLinksKeyByTag { + tag: tag.clone(), + id: ProcessUniqueId::new().to_string(), + }; + + let crud_status = match link_status_request { + LinksStatusRequestKind::All => None, + LinksStatusRequestKind::Live => Some(CrudStatus::Live), + LinksStatusRequestKind::Deleted => Some(CrudStatus::Deleted), + }; + let action_wrapper = ActionWrapper::new(Action::GetLinksCountByTag((key.clone(), crud_status))); + dispatch_action(context.action_channel(), action_wrapper.clone()); + + /*let key_inner = key.clone(); + let context_inner = context.clone(); + let _ = thread::spawn(move || { + thread::sleep(timeout.into()); + let action_wrapper = ActionWrapper::new(Action::GetLinksTimeout(key_inner)); + dispatch_action(context_inner.action_channel(), action_wrapper.clone()); + });*/ + + await!(GetLinksCountByTagFuture { + context: context.clone(), + key + }) +} /// GetLinksFuture resolves to a HcResult>. /// Tracks the state of the network module @@ -81,3 +113,30 @@ impl Future for GetLinksCountFuture { } } } + +/// GetLinksFuture resolves to a HcResult>. +/// Tracks the state of the network module +pub struct GetLinksCountByTagFuture { + context: Arc, + key: GetLinksKeyByTag, +} + +impl Future for GetLinksCountByTagFuture { + type Output = HcResult; + + fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { + let state = self.context.state().unwrap().network(); + if let Err(error) = state.initialized() { + return Poll::Ready(Err(error)); + } + // + // TODO: connect the waker to state updates for performance reasons + // See: https://github.com/holochain/holochain-rust/issues/314 + // + lw.wake(); + match state.get_links_result_count_by_tag.get(&self.key) { + Some(Some(result)) => Poll::Ready(result.clone()), + _ => Poll::Pending, + } + } +} diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index a6f3e7a412..dc933cb38c 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -30,6 +30,22 @@ fn get_links( .collect::>() } +fn get_links_by_tag( + context: &Arc, + tag: String, + crud_status: Option, +) -> Vec<(Address, CrudStatus)> { + context + .state() + .unwrap() + .dht() + .get_links_by_tag(tag, crud_status) + .unwrap_or(BTreeSet::new()) + .into_iter() + .map(|eav_crud| (eav_crud.0.value(), eav_crud.1)) + .collect::>() +} + fn get_entry(context: &Arc, address: Address) -> Option { nucleus::actions::get_entry::get_entry_with_meta(&context, address.clone()) .map(|entry_with_meta_opt| { @@ -100,6 +116,20 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc link_type.clone(), tag.clone(), ))) + }, + Ok(NetworkQuery::GetLinksByTag(tag, crud)) => { + let links_count = get_links_by_tag( + &context, + tag.clone(), + crud.clone(), + ) + .len(); + ActionWrapper::new(Action::RespondGetLinksCount(( + query_data, + links_count, + String::default(), + tag.clone(), + ))) } Ok(NetworkQuery::GetEntry) => { let maybe_entry = get_entry(&context, query_data.entry_address.clone()); diff --git a/core/src/network/query.rs b/core/src/network/query.rs index cc4545c4b8..da9bcc8823 100644 --- a/core/src/network/query.rs +++ b/core/src/network/query.rs @@ -7,6 +7,7 @@ pub enum NetworkQuery { GetEntry, GetLinks(String, String), GetLinksCount(String, String, Option), + GetLinksByTag(String,Option) } #[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] @@ -14,4 +15,5 @@ pub enum NetworkQueryResult { Entry(Option), Links(Vec<(Address, CrudStatus)>, String, String), LinksCount(usize, String, String), + LinksCountByTag(usize,String) } diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs index 120d12823b..6744d47eac 100644 --- a/core/src/network/reducers/get_links_count.rs +++ b/core/src/network/reducers/get_links_count.rs @@ -1,5 +1,5 @@ use crate::{ - action::{ActionWrapper, GetLinksKey}, + action::{ActionWrapper, GetLinksKey,GetLinksKeyByTag}, network::{query::NetworkQuery, reducers::send, state::NetworkState}, state::State, }; @@ -29,6 +29,26 @@ fn reduce_get_links_inner( ) } +fn reduce_get_links_inner_by_tag( + network_state: &mut NetworkState, + key: &GetLinksKeyByTag, + crud_status: Option, +) -> Result<(), HolochainError> { + network_state.initialized()?; + let query_json: JsonString = + NetworkQuery::GetLinksByTag(key.tag.clone(), crud_status).into(); + send( + network_state, + JsonProtocol::QueryEntry(QueryEntryData { + requester_agent_id: network_state.agent_id.clone().unwrap().into(), + request_id: key.id.clone(), + dna_address: network_state.dna_address.clone().unwrap(), + entry_address: HashString::from(String::default()), + query: query_json.to_string().into_bytes(), + }), + ) +} + pub fn reduce_get_links_count( network_state: &mut NetworkState, _root_state: &State, @@ -45,6 +65,22 @@ pub fn reduce_get_links_count( network_state.get_links_results.insert(key.clone(), result); } +pub fn reduce_get_links_count_by_tag( + network_state: &mut NetworkState, + _root_state: &State, + action_wrapper: &ActionWrapper, +) { + let action = action_wrapper.action(); + let (key, crud) = unwrap_to!(action => crate::action::Action::GetLinksCountByTag); + + let result = match reduce_get_links_inner_by_tag(network_state, &key, crud.clone()) { + Ok(()) => None, + Err(err) => Some(Err(err)), + }; + + network_state.get_links_result_count_by_tag.insert(key.clone(), result); +} + pub fn reduce_get_links_timeout( network_state: &mut NetworkState, _root_state: &State, diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index f75ed611a1..5bffeecbb5 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -23,7 +23,7 @@ use crate::{ reducers::{ get_entry::{reduce_get_entry, reduce_get_entry_timeout}, get_links::{reduce_get_links, reduce_get_links_timeout}, - get_links_count::reduce_get_links_count, + get_links_count::{reduce_get_links_count,reduce_get_links_count_by_tag}, get_validation_package::reduce_get_validation_package, handle_custom_send_response::reduce_handle_custom_send_response, handle_get_links_result::reduce_handle_get_links_result, @@ -60,6 +60,7 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::GetEntryTimeout(_) => Some(reduce_get_entry_timeout), Action::GetLinks(_) => Some(reduce_get_links), Action::GetLinksCount(_) => Some(reduce_get_links_count), + Action::GetLinksCountByTag(_) =>Some(reduce_get_links_count_by_tag), Action::GetLinksTimeout(_) => Some(reduce_get_links_timeout), Action::GetValidationPackage(_) => Some(reduce_get_validation_package), Action::HandleCustomSendResponse(_) => Some(reduce_handle_custom_send_response), diff --git a/core/src/network/state.rs b/core/src/network/state.rs index 2fb4f08548..3341f16273 100644 --- a/core/src/network/state.rs +++ b/core/src/network/state.rs @@ -1,5 +1,5 @@ use crate::{ - action::{ActionWrapper, GetEntryKey, GetLinksKey}, + action::{ActionWrapper, GetEntryKey, GetLinksKey,GetLinksKeyByTag}, network::{actions::ActionResponse, direct_message::DirectMessage}, }; use boolinator::*; @@ -63,6 +63,8 @@ pub struct NetworkState { pub get_links_results_count: HashMap, + pub get_links_result_count_by_tag : HashMap, + /// Here we store the results of get validation package processes. /// None means that we are still waiting for a result from the network. pub get_validation_package_results: HashMap, @@ -93,6 +95,7 @@ impl NetworkState { get_entry_with_meta_results: HashMap::new(), get_links_results: HashMap::new(), get_links_results_count: HashMap::new(), + get_links_result_count_by_tag : HashMap::new(), get_validation_package_results: HashMap::new(), direct_message_connections: HashMap::new(), custom_direct_message_replys: HashMap::new(), From 0f77919317667502c32df2194f6b68a5faa33c27 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 09:33:25 -0400 Subject: [PATCH 13/48] get_links_by_tag implemented --- core/src/action.rs | 4 +-- core/src/dht/dht_store.rs | 27 ++++++++++--------- core/src/network/actions/get_links_count.rs | 5 ++-- core/src/network/handler/query.rs | 20 ++++++++------ core/src/network/query.rs | 4 +-- core/src/network/reducers/get_links_count.rs | 9 ++++--- .../reducers/handle_get_links_result_count.rs | 13 +++++++++ core/src/network/reducers/mod.rs | 9 ++++--- core/src/network/state.rs | 6 ++--- .../nucleus/ribosome/api/get_links_count.rs | 2 +- core/src/workflows/get_links_count.rs | 19 +++++-------- hdk-rust/src/api/get_links.rs | 9 +++---- hdk-rust/src/api/mod.rs | 4 +-- wasm_utils/src/api_serialization/get_links.rs | 5 ++-- 14 files changed, 75 insertions(+), 61 deletions(-) diff --git a/core/src/action.rs b/core/src/action.rs index 4ba1f2395d..3e169177de 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -158,11 +158,12 @@ pub enum Action { GetLinks(GetLinksKey), GetLinksTimeout(GetLinksKey), GetLinksCount((GetLinksKey, Option)), - GetLinksCountByTag((GetLinksKeyByTag,Option)), + GetLinksCountByTag((GetLinksKeyByTag, Option)), RespondGetLinks((QueryEntryData, Vec<(Address, CrudStatus)>, String, String)), RespondGetLinksCount((QueryEntryData, usize, String, String)), HandleGetLinksResult((Vec<(Address, CrudStatus)>, GetLinksKey)), HandleGetLinksResultCount((usize, GetLinksKey)), + HandleGetLinksResultCountByTag((usize, GetLinksKeyByTag)), /// Makes the network module send a direct (node-to-node) message /// to the address given in [DirectMessageData](struct.DirectMessageData.html) @@ -262,7 +263,6 @@ pub struct GetLinksKey { /// response with this GetLinks request #[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)] pub struct GetLinksKeyByTag { - /// The link tag, None means get all the tags for a given type pub tag: String, diff --git a/core/src/dht/dht_store.rs b/core/src/dht/dht_store.rs index 9372114017..ddc0054c1d 100644 --- a/core/src/dht/dht_store.rs +++ b/core/src/dht/dht_store.rs @@ -71,28 +71,29 @@ pub fn create_get_links_eavi_query<'a>( )) } -pub fn create_get_links_by_tag_eavi_query<'a>(tag : String) -> Result, HolochainError> -{ - let tag_regex =Regex::new(&tag).map_err(|_| HolochainError::from("Invalid regex passed for tag"))?; +pub fn create_get_links_by_tag_eavi_query<'a>( + tag: String, +) -> Result, HolochainError> { + let tag_regex = + Regex::new(&tag).map_err(|_| HolochainError::from("Invalid regex passed for tag"))?; + let tombstone_tag_regex = tag_regex.clone(); Ok(EaviQuery::new( None.into(), EavFilter::predicate(move |attr: Attribute| match attr.clone() { - Attribute::LinkTag(_, query_tag) - | Attribute::RemovedLink(_, query_tag) => { + Attribute::LinkTag(_, query_tag) | Attribute::RemovedLink(_, query_tag) => { tag_regex.is_match(&query_tag) } _ => false, }), None.into(), IndexFilter::LatestByAttribute, - Some(EavFilter::predicate(move |attr: Attribute| match attr.clone() { - Attribute::RemovedLink(_, query_tag) => { - tag_regex.is_match(&query_tag) + Some(EavFilter::predicate(move |attr: Attribute| { + match attr.clone() { + Attribute::RemovedLink(_, query_tag) => tombstone_tag_regex.is_match(&query_tag), + _ => false, } - _ => false, - } - ))), - ) + })), + )) } impl DhtStore { @@ -131,7 +132,7 @@ impl DhtStore { .collect()) } - pub fn get_links_by_tag( + pub fn get_links_by_tag( &self, tag: String, crud_filter: Option, diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs index 6218c94fcb..050e9b7cb4 100644 --- a/core/src/network/actions/get_links_count.rs +++ b/core/src/network/actions/get_links_count.rs @@ -1,5 +1,5 @@ use crate::{ - action::{Action, ActionWrapper, GetLinksKey,GetLinksKeyByTag}, + action::{Action, ActionWrapper, GetLinksKey, GetLinksKeyByTag}, context::Context, instance::dispatch_action, }; @@ -53,7 +53,6 @@ pub async fn get_links_count( }) } - pub async fn get_links_count_by_tag( context: Arc, tag: String, @@ -83,7 +82,7 @@ pub async fn get_links_count_by_tag( await!(GetLinksCountByTagFuture { context: context.clone(), - key + key }) } diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index dc933cb38c..7b05763826 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -1,5 +1,5 @@ use crate::{ - action::{Action, ActionWrapper, GetEntryKey, GetLinksKey}, + action::{Action, ActionWrapper, GetEntryKey, GetLinksKey, GetLinksKeyByTag}, context::Context, entry::CanPublish, instance::dispatch_action, @@ -116,14 +116,9 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc link_type.clone(), tag.clone(), ))) - }, + } Ok(NetworkQuery::GetLinksByTag(tag, crud)) => { - let links_count = get_links_by_tag( - &context, - tag.clone(), - crud.clone(), - ) - .len(); + let links_count = get_links_by_tag(&context, tag.clone(), crud.clone()).len(); ActionWrapper::new(Action::RespondGetLinksCount(( query_data, links_count, @@ -183,6 +178,15 @@ pub fn handle_query_entry_result(query_result_data: QueryEntryResultData, contex }, ))) } + Ok(NetworkQueryResult::LinksCountByTag(links_count, tag)) => { + ActionWrapper::new(Action::HandleGetLinksResultCountByTag(( + links_count, + GetLinksKeyByTag { + tag: tag.clone(), + id: query_result_data.request_id.clone(), + }, + ))) + } err => { context.log(format!( "err/net: Error ({:?}) deserializing QueryResult {:?}", diff --git a/core/src/network/query.rs b/core/src/network/query.rs index da9bcc8823..561e07013c 100644 --- a/core/src/network/query.rs +++ b/core/src/network/query.rs @@ -7,7 +7,7 @@ pub enum NetworkQuery { GetEntry, GetLinks(String, String), GetLinksCount(String, String, Option), - GetLinksByTag(String,Option) + GetLinksByTag(String, Option), } #[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] @@ -15,5 +15,5 @@ pub enum NetworkQueryResult { Entry(Option), Links(Vec<(Address, CrudStatus)>, String, String), LinksCount(usize, String, String), - LinksCountByTag(usize,String) + LinksCountByTag(usize, String), } diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs index 6744d47eac..559592f171 100644 --- a/core/src/network/reducers/get_links_count.rs +++ b/core/src/network/reducers/get_links_count.rs @@ -1,5 +1,5 @@ use crate::{ - action::{ActionWrapper, GetLinksKey,GetLinksKeyByTag}, + action::{ActionWrapper, GetLinksKey, GetLinksKeyByTag}, network::{query::NetworkQuery, reducers::send, state::NetworkState}, state::State, }; @@ -35,8 +35,7 @@ fn reduce_get_links_inner_by_tag( crud_status: Option, ) -> Result<(), HolochainError> { network_state.initialized()?; - let query_json: JsonString = - NetworkQuery::GetLinksByTag(key.tag.clone(), crud_status).into(); + let query_json: JsonString = NetworkQuery::GetLinksByTag(key.tag.clone(), crud_status).into(); send( network_state, JsonProtocol::QueryEntry(QueryEntryData { @@ -78,7 +77,9 @@ pub fn reduce_get_links_count_by_tag( Err(err) => Some(Err(err)), }; - network_state.get_links_result_count_by_tag.insert(key.clone(), result); + network_state + .get_links_result_count_by_tag + .insert(key.clone(), result); } pub fn reduce_get_links_timeout( diff --git a/core/src/network/reducers/handle_get_links_result_count.rs b/core/src/network/reducers/handle_get_links_result_count.rs index bd17ad343b..b8e73df77a 100644 --- a/core/src/network/reducers/handle_get_links_result_count.rs +++ b/core/src/network/reducers/handle_get_links_result_count.rs @@ -11,3 +11,16 @@ pub fn reduce_handle_get_links_count( .get_links_results_count .insert(key.clone(), Some(Ok(links_count.clone()))); } + +pub fn reduce_handle_get_links_count_by_tag( + network_state: &mut NetworkState, + _root_state: &State, + action_wrapper: &ActionWrapper, +) { + let action = action_wrapper.action(); + let (links_count, key) = + unwrap_to!(action => crate::action::Action::HandleGetLinksResultCountByTag); + network_state + .get_links_result_count_by_tag + .insert(key.clone(), Some(Ok(links_count.clone()))); +} diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index 5bffeecbb5..ecbc679d31 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -23,11 +23,13 @@ use crate::{ reducers::{ get_entry::{reduce_get_entry, reduce_get_entry_timeout}, get_links::{reduce_get_links, reduce_get_links_timeout}, - get_links_count::{reduce_get_links_count,reduce_get_links_count_by_tag}, + get_links_count::{reduce_get_links_count, reduce_get_links_count_by_tag}, get_validation_package::reduce_get_validation_package, handle_custom_send_response::reduce_handle_custom_send_response, handle_get_links_result::reduce_handle_get_links_result, - handle_get_links_result_count::reduce_handle_get_links_count, + handle_get_links_result_count::{ + reduce_handle_get_links_count, reduce_handle_get_links_count_by_tag, + }, handle_get_result::reduce_handle_get_result, handle_get_validation_package::reduce_handle_get_validation_package, init::reduce_init, @@ -60,7 +62,7 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::GetEntryTimeout(_) => Some(reduce_get_entry_timeout), Action::GetLinks(_) => Some(reduce_get_links), Action::GetLinksCount(_) => Some(reduce_get_links_count), - Action::GetLinksCountByTag(_) =>Some(reduce_get_links_count_by_tag), + Action::GetLinksCountByTag(_) => Some(reduce_get_links_count_by_tag), Action::GetLinksTimeout(_) => Some(reduce_get_links_timeout), Action::GetValidationPackage(_) => Some(reduce_get_validation_package), Action::HandleCustomSendResponse(_) => Some(reduce_handle_custom_send_response), @@ -68,6 +70,7 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::HandleGetLinksResult(_) => Some(reduce_handle_get_links_result), Action::HandleGetValidationPackage(_) => Some(reduce_handle_get_validation_package), Action::HandleGetLinksResultCount(_) => Some(reduce_handle_get_links_count), + Action::HandleGetLinksResultCountByTag(_) => Some(reduce_handle_get_links_count_by_tag), Action::InitNetwork(_) => Some(reduce_init), Action::Publish(_) => Some(reduce_publish), Action::ResolveDirectConnection(_) => Some(reduce_resolve_direct_connection), diff --git a/core/src/network/state.rs b/core/src/network/state.rs index 3341f16273..36485d37e6 100644 --- a/core/src/network/state.rs +++ b/core/src/network/state.rs @@ -1,5 +1,5 @@ use crate::{ - action::{ActionWrapper, GetEntryKey, GetLinksKey,GetLinksKeyByTag}, + action::{ActionWrapper, GetEntryKey, GetLinksKey, GetLinksKeyByTag}, network::{actions::ActionResponse, direct_message::DirectMessage}, }; use boolinator::*; @@ -63,7 +63,7 @@ pub struct NetworkState { pub get_links_results_count: HashMap, - pub get_links_result_count_by_tag : HashMap, + pub get_links_result_count_by_tag: HashMap, /// Here we store the results of get validation package processes. /// None means that we are still waiting for a result from the network. @@ -95,7 +95,7 @@ impl NetworkState { get_entry_with_meta_results: HashMap::new(), get_links_results: HashMap::new(), get_links_results_count: HashMap::new(), - get_links_result_count_by_tag : HashMap::new(), + get_links_result_count_by_tag: HashMap::new(), get_validation_package_results: HashMap::new(), direct_message_connections: HashMap::new(), custom_direct_message_replys: HashMap::new(), diff --git a/core/src/nucleus/ribosome/api/get_links_count.rs b/core/src/nucleus/ribosome/api/get_links_count.rs index ca412dcd6b..9622cb54ba 100644 --- a/core/src/nucleus/ribosome/api/get_links_count.rs +++ b/core/src/nucleus/ribosome/api/get_links_count.rs @@ -10,7 +10,7 @@ pub fn invoke_get_links_count(runtime: &mut Runtime, args: &RuntimeArgs) -> Zome let context = runtime.context()?; // deserialize args let args_str = runtime.load_json_string_from_args(&args); - + let input = match GetLinksBy::try_from(args_str.clone()) { Ok(input) => { context.log(format!( diff --git a/core/src/workflows/get_links_count.rs b/core/src/workflows/get_links_count.rs index 98c09221c9..51333508bf 100644 --- a/core/src/workflows/get_links_count.rs +++ b/core/src/workflows/get_links_count.rs @@ -1,28 +1,23 @@ use crate::{context::Context, network::actions::get_links_count::get_links_count}; use holochain_core_types::error::HolochainError; -use holochain_wasm_utils::api_serialization::get_links::{ GetLinksResultCount,GetLinksBy}; +use holochain_wasm_utils::api_serialization::get_links::{GetLinksBy, GetLinksResultCount}; use std::sync::Arc; pub async fn get_link_result_count_workflow<'a>( context: Arc, link_args: &'a GetLinksBy, ) -> Result { - let links_count = match link_args - { - GetLinksBy::GetLinksArgs(link_args)=> - { - await!(get_links_count(context, + let links_count = match link_args { + GetLinksBy::GetLinksArgs(link_args) => await!(get_links_count( + context, link_args.entry_address.clone(), link_args.link_type.clone(), link_args.tag.clone(), link_args.options.timeout.clone(), - link_args.options.status_request.clone()))? - }, - GetLinksBy::Tag(_,_) => - { - unimplemented!("Not yet") - } + link_args.options.status_request.clone() + ))?, + GetLinksBy::Tag(_, _) => unimplemented!("Not yet"), }; //get links based on status request, all for everything, deleted for deleted links and live for active links diff --git a/hdk-rust/src/api/get_links.rs b/hdk-rust/src/api/get_links.rs index 93a352133a..2a361acdb2 100644 --- a/hdk-rust/src/api/get_links.rs +++ b/hdk-rust/src/api/get_links.rs @@ -5,7 +5,7 @@ use holochain_core_types::{entry::Entry, link::LinkMatch}; use holochain_persistence_api::{cas::content::Address, hash::HashString}; use holochain_wasm_utils::api_serialization::{ get_entry::{GetEntryOptions, GetEntryResult, GetEntryResultItem, GetEntryResultType}, - get_links::{GetLinksArgs, GetLinksOptions, GetLinksResult, GetLinksResultCount,GetLinksBy}, + get_links::{GetLinksArgs, GetLinksBy, GetLinksOptions, GetLinksResult, GetLinksResultCount}, }; /// Consumes four values; the address of an entry get get links from (the base), the type of the links @@ -99,16 +99,15 @@ pub fn get_links_count( get_links_count_with_options(base, link_type, tag, GetLinksOptions::default()) } -pub fn get_links_by_tag( +pub fn get_links_count_by_tag( tag: LinkMatch<&str>, - options : GetLinksOptions + options: GetLinksOptions, ) -> ZomeApiResult { let tag_re = tag.to_regex_string()?; - let get_links_args = GetLinksBy::Tag(tag_re,options); + let get_links_args = GetLinksBy::Tag(tag_re, options); Dispatch::GetLinksCount.with_input(get_links_args) } - /// Helper function for get_links. Returns a vector with the default return results. pub fn get_links( base: &Address, diff --git a/hdk-rust/src/api/mod.rs b/hdk-rust/src/api/mod.rs index 942e61539b..7d10ba0a53 100644 --- a/hdk-rust/src/api/mod.rs +++ b/hdk-rust/src/api/mod.rs @@ -53,8 +53,8 @@ pub use self::{ entry_type_properties::entry_type_properties, get_entry::{get_entry, get_entry_history, get_entry_initial, get_entry_result}, get_links::{ - get_links, get_links_and_load, get_links_count, get_links_count_with_options, - get_links_result, get_links_with_options, + get_links, get_links_and_load, get_links_count, get_links_count_by_tag, + get_links_count_with_options, get_links_result, get_links_with_options, }, keystore::{ keystore_derive_key, keystore_derive_seed, keystore_get_public_key, keystore_list, diff --git a/wasm_utils/src/api_serialization/get_links.rs b/wasm_utils/src/api_serialization/get_links.rs index 94cb90f170..4ac6bc03b6 100644 --- a/wasm_utils/src/api_serialization/get_links.rs +++ b/wasm_utils/src/api_serialization/get_links.rs @@ -52,10 +52,9 @@ pub struct GetLinksResult { } #[derive(Deserialize, Debug, Serialize, DefaultJson, Clone, PartialEq, Hash, Eq)] -pub enum GetLinksBy -{ +pub enum GetLinksBy { GetLinksArgs(GetLinksArgs), - Tag(String,GetLinksOptions) + Tag(String, GetLinksOptions), } #[derive(Deserialize, Serialize, Debug, DefaultJson)] From 85c5d4f52bec8ff8a920d1af8bfc3e6208b6461d Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 09:57:17 -0400 Subject: [PATCH 14/48] Update lib.rs --- app_spec/zomes/simple/code/src/lib.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index cc7586d023..156a4341ee 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -58,6 +58,12 @@ pub fn handle_create_my_link(base: Address,target : String) -> ZomeApiResult<()> Ok(()) } +pub fn handle_create_my_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()> { + let address = hdk::commit_entry(&simple_entry(target))?; + hdk::link_entries(&base, &HashString::from(address), "authored_simple_posts", &tag)?; + Ok(()) +} + pub fn handle_delete_my_link(base: Address,target : String) -> ZomeApiResult<()> { let address = hdk::entry_address(&simple_entry(target))?; hdk::remove_link(&base, &HashString::from(address), "authored_simple_posts", "")?; @@ -83,6 +89,15 @@ pub fn handle_get_my_links_count(agent : Address,status_request:Option) ->ZomeApiResult +{ + let options = GetLinksOptions{ + status_request : status_request.unwrap_or(LinksStatusRequestKind::All), + ..GetLinksOptions::default() + }; + hdk::get_links_count_by_tag(LinkMatch::Exactly(&tag),options) +} + pub fn handle_test_emit_signal(message: String) -> ZomeApiResult<()> { #[derive(Debug, Serialize, Deserialize, DefaultJson)] struct SignalPayload { @@ -149,6 +164,11 @@ define_zome! { outputs: |result: ZomeApiResult<()>|, handler: handle_create_my_link } + create_link_with_tag: { + inputs: |base : Address,target:String,tag:String|, + outputs: |result: ZomeApiResult<()>|, + handler: handle_create_my_link_with_tag + } delete_link: { inputs: |base : Address,target:String|, outputs: |result: ZomeApiResult<()>|, @@ -164,6 +184,11 @@ define_zome! { outputs: |result: ZomeApiResult|, handler: handle_get_my_links_count } + get_my_links_by_tag_count: { + inputs: |tag: String,status_request:Option|, + outputs: |result: ZomeApiResult|, + handler: handle_get_my_links_by_tag_count + } encrypt :{ inputs : |payload: String|, outputs: |result: ZomeApiResult|, From 504364a980370e49feeb98fe88cdbbb78e206109 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 12:03:28 -0400 Subject: [PATCH 15/48] Fixed problem with loop --- app_spec/zomes/blog/code/src/memo.rs | 1 - app_spec/zomes/blog/code/src/post.rs | 1 - app_spec/zomes/simple/code/src/lib.rs | 4 +- core/src/action.rs | 1 + core/src/network/handler/query.rs | 4 +- .../reducers/handle_get_links_result_count.rs | 1 + core/src/network/reducers/mod.rs | 3 +- .../reducers/respond_get_links_count.rs | 49 +++++++++++++++++++ core/src/workflows/get_links_count.rs | 7 ++- 9 files changed, 62 insertions(+), 9 deletions(-) diff --git a/app_spec/zomes/blog/code/src/memo.rs b/app_spec/zomes/blog/code/src/memo.rs index b93d252d98..41917e533e 100644 --- a/app_spec/zomes/blog/code/src/memo.rs +++ b/app_spec/zomes/blog/code/src/memo.rs @@ -101,7 +101,6 @@ mod tests { assert_eq!(expected_name, memo_definition.name.clone()); let expected_definition = EntryTypeDef { - description: "A private memo entry type.".to_string(), linked_from: vec![], links_to: Vec::new(), sharing: Sharing::Private, diff --git a/app_spec/zomes/blog/code/src/post.rs b/app_spec/zomes/blog/code/src/post.rs index 7362881a6b..caddf3e134 100644 --- a/app_spec/zomes/blog/code/src/post.rs +++ b/app_spec/zomes/blog/code/src/post.rs @@ -152,7 +152,6 @@ mod tests { assert_eq!(expected_name, post_definition.name.clone()); let expected_definition = EntryTypeDef { - description: "blog entry post".to_string(), linked_from: vec![ LinkedFrom { base_type: "%agent_id".to_string(), diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index 156a4341ee..27325cec09 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -184,7 +184,7 @@ define_zome! { outputs: |result: ZomeApiResult|, handler: handle_get_my_links_count } - get_my_links_by_tag_count: { + get_my_links_count_by_tag: { inputs: |tag: String,status_request:Option|, outputs: |result: ZomeApiResult|, handler: handle_get_my_links_by_tag_count @@ -207,7 +207,7 @@ define_zome! { ] traits: { - hc_public [create_link, delete_link, get_my_links, test_emit_signal,get_my_links_count] + hc_public [create_link, delete_link, get_my_links, test_emit_signal,get_my_links_count,create_link_with_tag,get_my_links_count_by_tag] } } diff --git a/core/src/action.rs b/core/src/action.rs index 3e169177de..8ae5d88cd3 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -161,6 +161,7 @@ pub enum Action { GetLinksCountByTag((GetLinksKeyByTag, Option)), RespondGetLinks((QueryEntryData, Vec<(Address, CrudStatus)>, String, String)), RespondGetLinksCount((QueryEntryData, usize, String, String)), + RespondGetLinksCountByTag((QueryEntryData, usize, String)), HandleGetLinksResult((Vec<(Address, CrudStatus)>, GetLinksKey)), HandleGetLinksResultCount((usize, GetLinksKey)), HandleGetLinksResultCountByTag((usize, GetLinksKeyByTag)), diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index 7b05763826..ffe847119c 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -119,10 +119,10 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc } Ok(NetworkQuery::GetLinksByTag(tag, crud)) => { let links_count = get_links_by_tag(&context, tag.clone(), crud.clone()).len(); - ActionWrapper::new(Action::RespondGetLinksCount(( + println!("links count {:?}",links_count.clone()); + ActionWrapper::new(Action::RespondGetLinksCountByTag(( query_data, links_count, - String::default(), tag.clone(), ))) } diff --git a/core/src/network/reducers/handle_get_links_result_count.rs b/core/src/network/reducers/handle_get_links_result_count.rs index b8e73df77a..5e34d365aa 100644 --- a/core/src/network/reducers/handle_get_links_result_count.rs +++ b/core/src/network/reducers/handle_get_links_result_count.rs @@ -17,6 +17,7 @@ pub fn reduce_handle_get_links_count_by_tag( _root_state: &State, action_wrapper: &ActionWrapper, ) { + println!("handle my links"); let action = action_wrapper.action(); let (links_count, key) = unwrap_to!(action => crate::action::Action::HandleGetLinksResultCountByTag); diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index ecbc679d31..c4fa0572a6 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -38,7 +38,7 @@ use crate::{ respond_fetch::reduce_respond_fetch_data, respond_get::reduce_respond_get, respond_get_links::reduce_respond_get_links, - respond_get_links_count::reduce_respond_get_links_count, + respond_get_links_count::{reduce_respond_get_links_count,reduce_respond_get_links_count_by_tag}, send_direct_message::{reduce_send_direct_message, reduce_send_direct_message_timeout}, }, state::NetworkState, @@ -78,6 +78,7 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::RespondGet(_) => Some(reduce_respond_get), Action::RespondGetLinks(_) => Some(reduce_respond_get_links), Action::RespondGetLinksCount(_) => Some(reduce_respond_get_links_count), + Action::RespondGetLinksCountByTag(_) =>Some(reduce_respond_get_links_count_by_tag), Action::SendDirectMessage(_) => Some(reduce_send_direct_message), Action::SendDirectMessageTimeout(_) => Some(reduce_send_direct_message_timeout), _ => None, diff --git a/core/src/network/reducers/respond_get_links_count.rs b/core/src/network/reducers/respond_get_links_count.rs index df0664ac1f..15aae90180 100644 --- a/core/src/network/reducers/respond_get_links_count.rs +++ b/core/src/network/reducers/respond_get_links_count.rs @@ -36,6 +36,30 @@ fn reduce_respond_get_links_count_inner( ) } +/// Send back to network a HandleQueryEntryResult, no matter what. +/// Will return an empty content field if it actually doesn't have the data. +fn reduce_respond_get_links_count_inner_by_tag( + network_state: &mut NetworkState, + query_data: &QueryEntryData, + links_count: usize, + tag: String, +) -> Result<(), HolochainError> { + network_state.initialized()?; + let query_result_json: JsonString = + NetworkQueryResult::LinksCountByTag(links_count.clone(),tag).into(); + send( + network_state, + JsonProtocol::HandleQueryEntryResult(QueryEntryResultData { + request_id: query_data.request_id.clone(), + requester_agent_id: query_data.requester_agent_id.clone(), + dna_address: network_state.dna_address.clone().unwrap(), + responder_agent_id: network_state.agent_id.clone().unwrap().into(), + entry_address: query_data.entry_address.clone().into(), + query_result: query_result_json.to_string().into_bytes(), + }), + ) +} + pub fn reduce_respond_get_links_count( network_state: &mut NetworkState, _root_state: &State, @@ -60,3 +84,28 @@ pub fn reduce_respond_get_links_count( }), ); } + + +pub fn reduce_respond_get_links_count_by_tag( + network_state: &mut NetworkState, + _root_state: &State, + action_wrapper: &ActionWrapper, +) { + let action = action_wrapper.action(); + let (query_data, links_count, tag) = + unwrap_to!(action => crate::action::Action::RespondGetLinksCountByTag); + let result = reduce_respond_get_links_count_inner_by_tag( + network_state, + query_data, + links_count.clone(), + tag.clone(), + ); + + network_state.actions.insert( + action_wrapper.clone(), + ActionResponse::RespondGetLinksCount(match result { + Ok(_) => Ok(()), + Err(e) => Err(HolochainError::ErrorGeneric(e.to_string())), + }), + ); +} diff --git a/core/src/workflows/get_links_count.rs b/core/src/workflows/get_links_count.rs index 51333508bf..b8f89f4d6e 100644 --- a/core/src/workflows/get_links_count.rs +++ b/core/src/workflows/get_links_count.rs @@ -1,4 +1,4 @@ -use crate::{context::Context, network::actions::get_links_count::get_links_count}; +use crate::{context::Context, network::actions::get_links_count::{get_links_count,get_links_count_by_tag}}; use holochain_core_types::error::HolochainError; use holochain_wasm_utils::api_serialization::get_links::{GetLinksBy, GetLinksResultCount}; @@ -17,7 +17,10 @@ pub async fn get_link_result_count_workflow<'a>( link_args.options.timeout.clone(), link_args.options.status_request.clone() ))?, - GetLinksBy::Tag(_, _) => unimplemented!("Not yet"), + GetLinksBy::Tag(tag, options) => + { + await!(get_links_count_by_tag(context,tag.to_string(),options.timeout.clone(),options.status_request.clone()))? + } }; //get links based on status request, all for everything, deleted for deleted links and live for active links From cbd0ec3d86586d3ce7d87faca1f06023a8e494de Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 13:43:11 -0400 Subject: [PATCH 16/48] Updates to timeout --- app_spec/zomes/simple/code/src/lib.rs | 13 +++++++++- .../zomes/simple/code/src/lib.rs | 25 +++++++++++++++++++ core/src/action.rs | 1 + core/src/network/actions/get_links_count.rs | 8 +++--- core/src/network/reducers/get_links_count.rs | 19 ++++++++++++++ .../reducers/handle_get_links_result_count.rs | 1 - core/src/network/reducers/mod.rs | 3 ++- 7 files changed, 63 insertions(+), 7 deletions(-) diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index 27325cec09..50f6fc936d 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -70,6 +70,12 @@ pub fn handle_delete_my_link(base: Address,target : String) -> ZomeApiResult<()> Ok(()) } +pub fn handle_delete_my_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()> { + let address = hdk::entry_address(&simple_entry(target))?; + hdk::remove_link(&base, &HashString::from(address), "authored_simple_posts", &tag)?; + Ok(()) +} + pub fn handle_get_my_links(agent : Address,status_request:Option) ->ZomeApiResult { @@ -174,6 +180,11 @@ define_zome! { outputs: |result: ZomeApiResult<()>|, handler: handle_delete_my_link } + delete_link_with_tag: { + inputs: |base : Address,target:String,tag:String|, + outputs: |result: ZomeApiResult<()>|, + handler: handle_delete_my_link_with_tag + } get_my_links: { inputs: |base: Address,status_request:Option|, outputs: |result: ZomeApiResult|, @@ -207,7 +218,7 @@ define_zome! { ] traits: { - hc_public [create_link, delete_link, get_my_links, test_emit_signal,get_my_links_count,create_link_with_tag,get_my_links_count_by_tag] + hc_public [create_link, delete_link, get_my_links, test_emit_signal,get_my_links_count,create_link_with_tag,get_my_links_count_by_tag,delete_link_with_tag] } } diff --git a/app_spec_proc_macro/zomes/simple/code/src/lib.rs b/app_spec_proc_macro/zomes/simple/code/src/lib.rs index def63a3941..3fde49d608 100644 --- a/app_spec_proc_macro/zomes/simple/code/src/lib.rs +++ b/app_spec_proc_macro/zomes/simple/code/src/lib.rs @@ -107,6 +107,14 @@ pub mod simple { hdk::link_entries(&base, &address, "authored_simple_posts", "")?; Ok(()) } + + #[zome_fn("hc_public")] + pub fn create_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()> + { + let address = hdk::commit_entry(&simple_entry(target))?; + hdk::link_entries(&base, &address, "authored_simple_posts", &tag)?; + Ok(()) + } #[zome_fn("hc_public")] pub fn delete_link(base: Address,target : String) -> ZomeApiResult<()> { let address = hdk::entry_address(&simple_entry(target))?; @@ -114,6 +122,13 @@ pub mod simple { Ok(()) } + #[zome_fn("hc_public")] + pub fn delete_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()> { + let address = hdk::entry_address(&simple_entry(target))?; + hdk::remove_link(&base, &address, "authored_simple_posts", &tag)?; + Ok(()) + } + #[zome_fn("hc_public")] pub fn get_my_links(base: Address,status_request : Option) -> ZomeApiResult { @@ -134,6 +149,16 @@ pub mod simple { hdk::get_links_count_with_options(&base, LinkMatch::Exactly("authored_posts"), LinkMatch::Any,options) } + #[zome_fn("hc_public")] + pub fn get_my_links_by_tag_count(tag : String,status_request:Option) ->ZomeApiResult + { + let options = GetLinksOptions{ + status_request : status_request.unwrap_or(LinksStatusRequestKind::All), + ..GetLinksOptions::default() + }; + hdk::get_links_count_by_tag(LinkMatch::Exactly(&tag),options) + } + #[zome_fn("hc_public")] pub fn test_emit_signal(message: String) -> ZomeApiResult<()> { #[derive(Debug, Serialize, Deserialize, DefaultJson)] diff --git a/core/src/action.rs b/core/src/action.rs index 8ae5d88cd3..77679e23df 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -157,6 +157,7 @@ pub enum Action { /// Last string is the stringified process unique id of this `hdk::get_links` call. GetLinks(GetLinksKey), GetLinksTimeout(GetLinksKey), + GetLinksTimeoutByTag(GetLinksKeyByTag), GetLinksCount((GetLinksKey, Option)), GetLinksCountByTag((GetLinksKeyByTag, Option)), RespondGetLinks((QueryEntryData, Vec<(Address, CrudStatus)>, String, String)), diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs index 050e9b7cb4..9dfe40dd53 100644 --- a/core/src/network/actions/get_links_count.rs +++ b/core/src/network/actions/get_links_count.rs @@ -56,7 +56,7 @@ pub async fn get_links_count( pub async fn get_links_count_by_tag( context: Arc, tag: String, - _timeout: Timeout, + timeout: Timeout, link_status_request: LinksStatusRequestKind, ) -> HcResult { let key = GetLinksKeyByTag { @@ -72,13 +72,13 @@ pub async fn get_links_count_by_tag( let action_wrapper = ActionWrapper::new(Action::GetLinksCountByTag((key.clone(), crud_status))); dispatch_action(context.action_channel(), action_wrapper.clone()); - /*let key_inner = key.clone(); + let key_inner = key.clone(); let context_inner = context.clone(); let _ = thread::spawn(move || { thread::sleep(timeout.into()); - let action_wrapper = ActionWrapper::new(Action::GetLinksTimeout(key_inner)); + let action_wrapper = ActionWrapper::new(Action::GetLinksTimeoutByTag(key_inner)); dispatch_action(context_inner.action_channel(), action_wrapper.clone()); - });*/ + }); await!(GetLinksCountByTagFuture { context: context.clone(), diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs index 559592f171..82a7a18733 100644 --- a/core/src/network/reducers/get_links_count.rs +++ b/core/src/network/reducers/get_links_count.rs @@ -100,3 +100,22 @@ pub fn reduce_get_links_timeout( .insert(key.clone(), Some(Err(HolochainError::Timeout))); } } + +pub fn reduce_get_links_timeout_by_tag( + network_state: &mut NetworkState, + _root_state: &State, + action_wrapper: &ActionWrapper, +) { + let action = action_wrapper.action(); + let key = unwrap_to!(action => crate::action::Action::GetLinksTimeoutByTag); + + if network_state.get_links_result_count_by_tag.get(key).is_none() { + return; + } + + if network_state.get_links_result_count_by_tag.get(key).unwrap().is_none() { + network_state + .get_links_result_count_by_tag + .insert(key.clone(), Some(Err(HolochainError::Timeout))); + } +} diff --git a/core/src/network/reducers/handle_get_links_result_count.rs b/core/src/network/reducers/handle_get_links_result_count.rs index 5e34d365aa..b8e73df77a 100644 --- a/core/src/network/reducers/handle_get_links_result_count.rs +++ b/core/src/network/reducers/handle_get_links_result_count.rs @@ -17,7 +17,6 @@ pub fn reduce_handle_get_links_count_by_tag( _root_state: &State, action_wrapper: &ActionWrapper, ) { - println!("handle my links"); let action = action_wrapper.action(); let (links_count, key) = unwrap_to!(action => crate::action::Action::HandleGetLinksResultCountByTag); diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index c4fa0572a6..247d94a208 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -23,7 +23,7 @@ use crate::{ reducers::{ get_entry::{reduce_get_entry, reduce_get_entry_timeout}, get_links::{reduce_get_links, reduce_get_links_timeout}, - get_links_count::{reduce_get_links_count, reduce_get_links_count_by_tag}, + get_links_count::{reduce_get_links_count, reduce_get_links_count_by_tag,reduce_get_links_timeout_by_tag}, get_validation_package::reduce_get_validation_package, handle_custom_send_response::reduce_handle_custom_send_response, handle_get_links_result::reduce_handle_get_links_result, @@ -64,6 +64,7 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::GetLinksCount(_) => Some(reduce_get_links_count), Action::GetLinksCountByTag(_) => Some(reduce_get_links_count_by_tag), Action::GetLinksTimeout(_) => Some(reduce_get_links_timeout), + Action::GetLinksTimeoutByTag(_)=>Some(reduce_get_links_timeout_by_tag), Action::GetValidationPackage(_) => Some(reduce_get_validation_package), Action::HandleCustomSendResponse(_) => Some(reduce_handle_custom_send_response), Action::HandleGetResult(_) => Some(reduce_handle_get_result), From e34657c006034a24133df2fe20aaefc55bf96a8f Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 13:44:32 -0400 Subject: [PATCH 17/48] added get by tag test --- app_spec/test/test.js | 71 +++++++++++++++++++ core/src/network/handler/query.rs | 2 +- core/src/network/reducers/get_links_count.rs | 13 +++- core/src/network/reducers/mod.rs | 13 ++-- .../reducers/respond_get_links_count.rs | 3 +- core/src/workflows/get_links_count.rs | 15 ++-- 6 files changed, 103 insertions(+), 14 deletions(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index c8de2ac170..a1d6196ae2 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -911,6 +911,77 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { +}) + + +scenario('get_links_crud_count_tag', async (s, t, { alice, bob }) => { + + //commits an entry and creates two links for alice + await alice.callSync("simple", "create_link_with_tag", + { "base": alice.agentId ,"target": "Holo world","tag":"tag1" } + ); + + const alice_result = await alice.callSync("simple", "create_link_with_tag", + { "base": bob.agentId ,"target": "Holo world 2","tag":"tag1" } + ); + + //get posts for alice from alice + const alice_posts_live= await alice.call("simple","get_my_links_count_by_tag", + { + "tag" : "tag1","status_request":"Live" + }) + + //get posts for alice from bob + const bob_posts_live= await alice.call("simple","get_my_links_count_by_tag", + { + "tag" : "tag1","status_request":"Live" + }) + + //make sure count equals to 2 + t.equal(2,alice_posts_live.Ok.count); + t.equal(2,bob_posts_live.Ok.count); + + //delete link + let deleted_link = await alice.callSync("simple","delete_link_with_tag", + { + "base" : alice.agentId, + "target" : "Holo world", + "tag" : "tag1" + }); + + + //get posts for alice from alice + const alice_posts_deleted= await alice.call("simple","get_my_links_count_by_tag", + { + "tag" : "tag1","status_request":"Deleted" + }) + + //get posts for alice from bob + const bob_posts_deleted= await alice.call("simple","get_my_links_count_by_tag", + { + "tag" : "tag1","status_request":"Deleted" + }) + + t.equal(1,alice_posts_deleted.Ok.count); + t.equal(1,bob_posts_deleted.Ok.count); + + + const alice_posts_all= await alice.call("simple","get_my_links_count_by_tag", + { + "tag" : "tag1","status_request":"All" + }) + + //get posts for alice from bob + const bob_posts_all= await alice.call("simple","get_my_links_count_by_tag", + { + "tag" : "tag1","status_request":"All" + }) + + t.equal(2,alice_posts_all.Ok.count); + t.equal(2,bob_posts_all.Ok.count); + + + }) scenario('create/get_post roundtrip', async (s, t, { alice }) => { diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index ffe847119c..89f3049c71 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -119,7 +119,7 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc } Ok(NetworkQuery::GetLinksByTag(tag, crud)) => { let links_count = get_links_by_tag(&context, tag.clone(), crud.clone()).len(); - println!("links count {:?}",links_count.clone()); + println!("links count {:?}", links_count.clone()); ActionWrapper::new(Action::RespondGetLinksCountByTag(( query_data, links_count, diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs index 82a7a18733..b31d5d6730 100644 --- a/core/src/network/reducers/get_links_count.rs +++ b/core/src/network/reducers/get_links_count.rs @@ -109,11 +109,20 @@ pub fn reduce_get_links_timeout_by_tag( let action = action_wrapper.action(); let key = unwrap_to!(action => crate::action::Action::GetLinksTimeoutByTag); - if network_state.get_links_result_count_by_tag.get(key).is_none() { + if network_state + .get_links_result_count_by_tag + .get(key) + .is_none() + { return; } - if network_state.get_links_result_count_by_tag.get(key).unwrap().is_none() { + if network_state + .get_links_result_count_by_tag + .get(key) + .unwrap() + .is_none() + { network_state .get_links_result_count_by_tag .insert(key.clone(), Some(Err(HolochainError::Timeout))); diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index 247d94a208..9c23c69323 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -23,7 +23,10 @@ use crate::{ reducers::{ get_entry::{reduce_get_entry, reduce_get_entry_timeout}, get_links::{reduce_get_links, reduce_get_links_timeout}, - get_links_count::{reduce_get_links_count, reduce_get_links_count_by_tag,reduce_get_links_timeout_by_tag}, + get_links_count::{ + reduce_get_links_count, reduce_get_links_count_by_tag, + reduce_get_links_timeout_by_tag, + }, get_validation_package::reduce_get_validation_package, handle_custom_send_response::reduce_handle_custom_send_response, handle_get_links_result::reduce_handle_get_links_result, @@ -38,7 +41,9 @@ use crate::{ respond_fetch::reduce_respond_fetch_data, respond_get::reduce_respond_get, respond_get_links::reduce_respond_get_links, - respond_get_links_count::{reduce_respond_get_links_count,reduce_respond_get_links_count_by_tag}, + respond_get_links_count::{ + reduce_respond_get_links_count, reduce_respond_get_links_count_by_tag, + }, send_direct_message::{reduce_send_direct_message, reduce_send_direct_message_timeout}, }, state::NetworkState, @@ -64,7 +69,7 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::GetLinksCount(_) => Some(reduce_get_links_count), Action::GetLinksCountByTag(_) => Some(reduce_get_links_count_by_tag), Action::GetLinksTimeout(_) => Some(reduce_get_links_timeout), - Action::GetLinksTimeoutByTag(_)=>Some(reduce_get_links_timeout_by_tag), + Action::GetLinksTimeoutByTag(_) => Some(reduce_get_links_timeout_by_tag), Action::GetValidationPackage(_) => Some(reduce_get_validation_package), Action::HandleCustomSendResponse(_) => Some(reduce_handle_custom_send_response), Action::HandleGetResult(_) => Some(reduce_handle_get_result), @@ -79,7 +84,7 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::RespondGet(_) => Some(reduce_respond_get), Action::RespondGetLinks(_) => Some(reduce_respond_get_links), Action::RespondGetLinksCount(_) => Some(reduce_respond_get_links_count), - Action::RespondGetLinksCountByTag(_) =>Some(reduce_respond_get_links_count_by_tag), + Action::RespondGetLinksCountByTag(_) => Some(reduce_respond_get_links_count_by_tag), Action::SendDirectMessage(_) => Some(reduce_send_direct_message), Action::SendDirectMessageTimeout(_) => Some(reduce_send_direct_message_timeout), _ => None, diff --git a/core/src/network/reducers/respond_get_links_count.rs b/core/src/network/reducers/respond_get_links_count.rs index 15aae90180..7155a76321 100644 --- a/core/src/network/reducers/respond_get_links_count.rs +++ b/core/src/network/reducers/respond_get_links_count.rs @@ -46,7 +46,7 @@ fn reduce_respond_get_links_count_inner_by_tag( ) -> Result<(), HolochainError> { network_state.initialized()?; let query_result_json: JsonString = - NetworkQueryResult::LinksCountByTag(links_count.clone(),tag).into(); + NetworkQueryResult::LinksCountByTag(links_count.clone(), tag).into(); send( network_state, JsonProtocol::HandleQueryEntryResult(QueryEntryResultData { @@ -85,7 +85,6 @@ pub fn reduce_respond_get_links_count( ); } - pub fn reduce_respond_get_links_count_by_tag( network_state: &mut NetworkState, _root_state: &State, diff --git a/core/src/workflows/get_links_count.rs b/core/src/workflows/get_links_count.rs index b8f89f4d6e..79b1066d3f 100644 --- a/core/src/workflows/get_links_count.rs +++ b/core/src/workflows/get_links_count.rs @@ -1,4 +1,7 @@ -use crate::{context::Context, network::actions::get_links_count::{get_links_count,get_links_count_by_tag}}; +use crate::{ + context::Context, + network::actions::get_links_count::{get_links_count, get_links_count_by_tag}, +}; use holochain_core_types::error::HolochainError; use holochain_wasm_utils::api_serialization::get_links::{GetLinksBy, GetLinksResultCount}; @@ -17,10 +20,12 @@ pub async fn get_link_result_count_workflow<'a>( link_args.options.timeout.clone(), link_args.options.status_request.clone() ))?, - GetLinksBy::Tag(tag, options) => - { - await!(get_links_count_by_tag(context,tag.to_string(),options.timeout.clone(),options.status_request.clone()))? - } + GetLinksBy::Tag(tag, options) => await!(get_links_count_by_tag( + context, + tag.to_string(), + options.timeout.clone(), + options.status_request.clone() + ))?, }; //get links based on status request, all for everything, deleted for deleted links and live for active links From a24cf72497acd89ccbd8a90a3a6b704abf56f8c6 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 13:58:41 -0400 Subject: [PATCH 18/48] updated spacing --- app_spec_proc_macro/zomes/simple/code/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec_proc_macro/zomes/simple/code/src/lib.rs b/app_spec_proc_macro/zomes/simple/code/src/lib.rs index 3fde49d608..3d9584b5f1 100644 --- a/app_spec_proc_macro/zomes/simple/code/src/lib.rs +++ b/app_spec_proc_macro/zomes/simple/code/src/lib.rs @@ -122,7 +122,7 @@ pub mod simple { Ok(()) } - #[zome_fn("hc_public")] + #[zome_fn("hc_public")] pub fn delete_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()> { let address = hdk::entry_address(&simple_entry(target))?; hdk::remove_link(&base, &address, "authored_simple_posts", &tag)?; From 408107c85b583e10caead993b33863a75dfe32c2 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 14:01:00 -0400 Subject: [PATCH 19/48] Update lib.rs --- app_spec_proc_macro/zomes/simple/code/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec_proc_macro/zomes/simple/code/src/lib.rs b/app_spec_proc_macro/zomes/simple/code/src/lib.rs index 3d9584b5f1..28b47181b1 100644 --- a/app_spec_proc_macro/zomes/simple/code/src/lib.rs +++ b/app_spec_proc_macro/zomes/simple/code/src/lib.rs @@ -150,7 +150,7 @@ pub mod simple { } #[zome_fn("hc_public")] - pub fn get_my_links_by_tag_count(tag : String,status_request:Option) ->ZomeApiResult + pub fn get_my_links_count_by_tag(tag : String,status_request:Option) ->ZomeApiResult { let options = GetLinksOptions{ status_request : status_request.unwrap_or(LinksStatusRequestKind::All), From 89ebdeb13948349fab0162ac56a9f34e30bdb3be Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 14:16:37 -0400 Subject: [PATCH 20/48] Update lib.rs --- app_spec/zomes/simple/code/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index 50f6fc936d..e776ce0c17 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -218,7 +218,7 @@ define_zome! { ] traits: { - hc_public [create_link, delete_link, get_my_links, test_emit_signal,get_my_links_count,create_link_with_tag,get_my_links_count_by_tag,delete_link_with_tag] + hc_public [create_link, delete_link, get_my_links, test_emit_signal,get_my_links_count,create_link_with_tag,get_my_links_count_by_tag,delete_link_with_tag,encrypt,decrypt] } } From 169cfdda3af34cca6951b2903f2ed58636dc8747 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 14:25:58 -0400 Subject: [PATCH 21/48] Update CHANGELOG-UNRELEASED.md --- CHANGELOG-UNRELEASED.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG-UNRELEASED.md b/CHANGELOG-UNRELEASED.md index b9b2b861df..b8b41ba2fd 100644 --- a/CHANGELOG-UNRELEASED.md +++ b/CHANGELOG-UNRELEASED.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `Encryption` and `Decryption` methods in the HDK [#1534](https://github.com/holochain/holochain-rust/pull/1534) - Adds `hc hash` CLI subcommand. Can be used to compute the hash of the DNA in the current dist directory or passed a path to a DNA with the --path flag [#1562](https://github.com/holochain/holochain-rust/pull/1562) - Adds a --dna flag to the CLI so `hc run` can run DNAs outside the standard ./dist/ directory [1561](https://github.com/holochain/holochain-rust/pull/1561) +- Added a `get_links_count` and `get_links_count_by_tag` method which allows the user to get number of links by base , target or just by the tag. [#1568](https://github.com/holochain/holochain-rust/pull/1568) ### Changed From 6a2f87c40fbd7b90bd96ab3c802ee5ed154d3ce6 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 15:48:29 -0400 Subject: [PATCH 22/48] updated app_spec --- app_spec/zomes/simple/code/src/lib.rs | 2 +- app_spec_proc_macro/zomes/simple/code/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index e776ce0c17..e332fe2b5d 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -92,7 +92,7 @@ pub fn handle_get_my_links_count(agent : Address,status_request:Option) ->ZomeApiResult diff --git a/app_spec_proc_macro/zomes/simple/code/src/lib.rs b/app_spec_proc_macro/zomes/simple/code/src/lib.rs index 28b47181b1..dbe4220bdc 100644 --- a/app_spec_proc_macro/zomes/simple/code/src/lib.rs +++ b/app_spec_proc_macro/zomes/simple/code/src/lib.rs @@ -146,7 +146,7 @@ pub mod simple { status_request : status_request.unwrap_or(LinksStatusRequestKind::All), ..GetLinksOptions::default() }; - hdk::get_links_count_with_options(&base, LinkMatch::Exactly("authored_posts"), LinkMatch::Any,options) + hdk::get_links_count_with_options(&base, LinkMatch::Exactly("authored_simple_posts"), LinkMatch::Any,options) } #[zome_fn("hc_public")] From f58c576046b79fa0928514c6478b28a49f9331ad Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 3 Jul 2019 15:50:47 -0400 Subject: [PATCH 23/48] updated docs --- hdk-rust/src/api/call.rs | 2 +- hdk-rust/src/api/send.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/hdk-rust/src/api/call.rs b/hdk-rust/src/api/call.rs index a09a928fca..09b6491f13 100644 --- a/hdk-rust/src/api/call.rs +++ b/hdk-rust/src/api/call.rs @@ -167,7 +167,7 @@ use holochain_wasm_utils::api_serialization::ZomeFnCallArgs; /// # pub fn hc_debug(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } /// # #[no_mangle] /// # pub fn hc_get_links(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } -/// # #[no_mangle] +/// #[no_mangle] /// # pub fn hc_get_links_count(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } /// # #[no_mangle] /// # pub fn hc_link_entries(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } diff --git a/hdk-rust/src/api/send.rs b/hdk-rust/src/api/send.rs index de4d7f8bd8..b2521d9810 100644 --- a/hdk-rust/src/api/send.rs +++ b/hdk-rust/src/api/send.rs @@ -66,6 +66,8 @@ use holochain_wasm_utils::api_serialization::send::{SendArgs, SendOptions}; /// # #[no_mangle] /// # pub fn hc_get_links(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } /// # #[no_mangle] +/// # pub fn hc_get_links_count(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } +/// # #[no_mangle] /// # pub fn hc_link_entries(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } /// # #[no_mangle] /// # pub fn hc_remove_link(_: RibosomeEncodingBits) -> RibosomeEncodingBits { RibosomeEncodedValue::Success.into() } From 26913eb73934269090557ae7965e67e5c3d5880f Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Thu, 4 Jul 2019 09:37:05 -0400 Subject: [PATCH 24/48] removed pritnln --- core/src/network/handler/query.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index 89f3049c71..ee08864957 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -119,7 +119,6 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc } Ok(NetworkQuery::GetLinksByTag(tag, crud)) => { let links_count = get_links_by_tag(&context, tag.clone(), crud.clone()).len(); - println!("links count {:?}", links_count.clone()); ActionWrapper::new(Action::RespondGetLinksCountByTag(( query_data, links_count, From 3e0ed469481abb58ef241678ccbf954f47350572 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Thu, 4 Jul 2019 13:38:28 -0400 Subject: [PATCH 25/48] changes to test --- app_spec/test/test.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index 3bd5cc36f8..232b1b9265 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -856,22 +856,22 @@ scenario('get_links_crud', async (s, t, { alice, bob }) => { scenario('get_links_crud_count', async (s, t, { alice, bob }) => { //commits an entry and creates two links for alice - await alice.callSync("simple", "create_link", + await alice.app.callSync("simple", "create_link", { "base": alice.agentId ,"target": "Holo world" } ); - const alice_result = await alice.callSync("simple", "create_link", + const alice_result = await alice.app.callSync("simple", "create_link", { "base": alice.agentId ,"target": "Holo world 2" } ); //get posts for alice from alice - const alice_posts_live= await alice.call("simple","get_my_links_count", + const alice_posts_live= await alice..app.call("simple","get_my_links_count", { "base" : alice.agentId,"status_request":"Live" }) //get posts for alice from bob - const bob_posts_live= await bob.call("simple","get_my_links_count", + const bob_posts_live= await bob.app.call("simple","get_my_links_count", { "base" : alice.agentId, "status_request":"Live" @@ -884,21 +884,21 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { ////delete the holo world post from the links alice created - await alice.callSync("simple","delete_link", + await alice.app.callSync("simple","delete_link", { "base" : alice.agentId, "target" : "Holo world" }); //get all bob posts - const bob_posts_deleted = await bob.call("simple","get_my_links_count", + const bob_posts_deleted = await bob.app.call("simple","get_my_links_count", { "base" : alice.agentId, "status_request" : "Deleted" }); // get all posts with a deleted status from alice - const alice_posts_deleted = await alice.call("simple","get_my_links_count", + const alice_posts_deleted = await alice.app.call("simple","get_my_links_count", { "base" : alice.agentId, "status_request" : "Deleted" @@ -917,22 +917,22 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { scenario('get_links_crud_count_tag', async (s, t, { alice, bob }) => { //commits an entry and creates two links for alice - await alice.callSync("simple", "create_link_with_tag", + await alice.app.callSync("simple", "create_link_with_tag", { "base": alice.agentId ,"target": "Holo world","tag":"tag1" } ); - const alice_result = await alice.callSync("simple", "create_link_with_tag", + const alice_result = await alice.app.callSync("simple", "create_link_with_tag", { "base": bob.agentId ,"target": "Holo world 2","tag":"tag1" } ); //get posts for alice from alice - const alice_posts_live= await alice.call("simple","get_my_links_count_by_tag", + const alice_posts_live= await alice.app.call("simple","get_my_links_count_by_tag", { "tag" : "tag1","status_request":"Live" }) //get posts for alice from bob - const bob_posts_live= await alice.call("simple","get_my_links_count_by_tag", + const bob_posts_live= await alice.app.call("simple","get_my_links_count_by_tag", { "tag" : "tag1","status_request":"Live" }) @@ -942,7 +942,7 @@ scenario('get_links_crud_count_tag', async (s, t, { alice, bob }) => { t.equal(2,bob_posts_live.Ok.count); //delete link - let deleted_link = await alice.callSync("simple","delete_link_with_tag", + let deleted_link = await alice.app.callSync("simple","delete_link_with_tag", { "base" : alice.agentId, "target" : "Holo world", @@ -951,13 +951,13 @@ scenario('get_links_crud_count_tag', async (s, t, { alice, bob }) => { //get posts for alice from alice - const alice_posts_deleted= await alice.call("simple","get_my_links_count_by_tag", + const alice_posts_deleted= await alice.app.call("simple","get_my_links_count_by_tag", { "tag" : "tag1","status_request":"Deleted" }) //get posts for alice from bob - const bob_posts_deleted= await alice.call("simple","get_my_links_count_by_tag", + const bob_posts_deleted= await alice.app.call("simple","get_my_links_count_by_tag", { "tag" : "tag1","status_request":"Deleted" }) @@ -966,13 +966,13 @@ scenario('get_links_crud_count_tag', async (s, t, { alice, bob }) => { t.equal(1,bob_posts_deleted.Ok.count); - const alice_posts_all= await alice.call("simple","get_my_links_count_by_tag", + const alice_posts_all= await alice.app.call("simple","get_my_links_count_by_tag", { "tag" : "tag1","status_request":"All" }) //get posts for alice from bob - const bob_posts_all= await alice.call("simple","get_my_links_count_by_tag", + const bob_posts_all= await alice.app.call("simple","get_my_links_count_by_tag", { "tag" : "tag1","status_request":"All" }) From ee969fdbf9b422e0e34de1e783f153ba408e632e Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Thu, 4 Jul 2019 13:51:20 -0400 Subject: [PATCH 26/48] fixed double period --- app_spec/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index 232b1b9265..e3d6dc14c1 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -865,7 +865,7 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { ); //get posts for alice from alice - const alice_posts_live= await alice..app.call("simple","get_my_links_count", + const alice_posts_live= await alice.app.call("simple","get_my_links_count", { "base" : alice.agentId,"status_request":"Live" }) From 7c2bb8ef2973cb03444318660a44bffbca027a7b Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Fri, 5 Jul 2019 09:42:01 -0400 Subject: [PATCH 27/48] fixed app_spec_tests --- app_spec/test/test.js | 20 ++++++++++---------- core/src/network/reducers/get_links_count.rs | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index e3d6dc14c1..3d1144b13b 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -857,23 +857,23 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { //commits an entry and creates two links for alice await alice.app.callSync("simple", "create_link", - { "base": alice.agentId ,"target": "Holo world" } + { "base": alice.app.agentId ,"target": "Holo world" } ); const alice_result = await alice.app.callSync("simple", "create_link", - { "base": alice.agentId ,"target": "Holo world 2" } + { "base": alice.app.agentId ,"target": "Holo world 2" } ); //get posts for alice from alice const alice_posts_live= await alice.app.call("simple","get_my_links_count", { - "base" : alice.agentId,"status_request":"Live" + "base" : alice.app.agentId,"status_request":"Live" }) //get posts for alice from bob const bob_posts_live= await bob.app.call("simple","get_my_links_count", { - "base" : alice.agentId, + "base" : alice.app.agentId, "status_request":"Live" }) @@ -886,21 +886,21 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { ////delete the holo world post from the links alice created await alice.app.callSync("simple","delete_link", { - "base" : alice.agentId, + "base" : alice.app.agentId, "target" : "Holo world" }); //get all bob posts const bob_posts_deleted = await bob.app.call("simple","get_my_links_count", { - "base" : alice.agentId, + "base" : alice.app.agentId, "status_request" : "Deleted" }); // get all posts with a deleted status from alice const alice_posts_deleted = await alice.app.call("simple","get_my_links_count", { - "base" : alice.agentId, + "base" : alice.app.agentId, "status_request" : "Deleted" }); @@ -918,11 +918,11 @@ scenario('get_links_crud_count_tag', async (s, t, { alice, bob }) => { //commits an entry and creates two links for alice await alice.app.callSync("simple", "create_link_with_tag", - { "base": alice.agentId ,"target": "Holo world","tag":"tag1" } + { "base": alice.app.agentId ,"target": "Holo world","tag":"tag1" } ); const alice_result = await alice.app.callSync("simple", "create_link_with_tag", - { "base": bob.agentId ,"target": "Holo world 2","tag":"tag1" } + { "base": bob.app.agentId ,"target": "Holo world 2","tag":"tag1" } ); //get posts for alice from alice @@ -944,7 +944,7 @@ scenario('get_links_crud_count_tag', async (s, t, { alice, bob }) => { //delete link let deleted_link = await alice.app.callSync("simple","delete_link_with_tag", { - "base" : alice.agentId, + "base" : alice.app.agentId, "target" : "Holo world", "tag" : "tag1" }); diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs index b31d5d6730..8966c5204d 100644 --- a/core/src/network/reducers/get_links_count.rs +++ b/core/src/network/reducers/get_links_count.rs @@ -61,7 +61,7 @@ pub fn reduce_get_links_count( Err(err) => Some(Err(err)), }; - network_state.get_links_results.insert(key.clone(), result); + network_state.get_links_results_count.insert(key.clone(), result); } pub fn reduce_get_links_count_by_tag( From 19be4fa71e8bff14172c469ad5ca56dd5caae01a Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Fri, 5 Jul 2019 09:42:35 -0400 Subject: [PATCH 28/48] cargo fmt --- core/src/network/reducers/get_links_count.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs index 8966c5204d..c3e0de579d 100644 --- a/core/src/network/reducers/get_links_count.rs +++ b/core/src/network/reducers/get_links_count.rs @@ -61,7 +61,9 @@ pub fn reduce_get_links_count( Err(err) => Some(Err(err)), }; - network_state.get_links_results_count.insert(key.clone(), result); + network_state + .get_links_results_count + .insert(key.clone(), result); } pub fn reduce_get_links_count_by_tag( From ee932bd7172eafd4978ce17632a6363d11a64fe2 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Fri, 5 Jul 2019 11:57:10 -0400 Subject: [PATCH 29/48] change to trigger CI --- app_spec/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index 3d1144b13b..ba3433aabd 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -108,7 +108,7 @@ scenario('show_env', async (s, t, { alice }) => { t.equal(result.Ok.agent_id, '{"nick":"alice::app","pub_sign_key":"' + alice.app.agentId + '"}') t.equal(result.Ok.properties, '{"test_property":"test-property-value"}') - // don't compare the public token because it changes every time we change the dna. + // don't compare the public token because it changes every time we change the dna t.deepEqual(result.Ok.cap_request.provenance, [ alice.app.agentId, 'HFQkrDmnSOcmGQnYNtaYZWj89rlIQVFg0PpEoeFyx/Qw6Oizy5PI+tcsO8wYrllkuVPPzF5P3pvbCctKkfyGBg==' ] ); From 25fc7edf0093382de9967eaf9e12099baa9e64cd Mon Sep 17 00:00:00 2001 From: Purple Hair Rust Bard Date: Fri, 5 Jul 2019 19:57:32 -0400 Subject: [PATCH 30/48] commti revert merge get tag --- core/src/action.rs | 12 ---- core/src/dht/dht_store.rs | 39 ------------- core/src/network/actions/get_links_count.rs | 61 +------------------- core/src/network/handler/query.rs | 24 -------- core/src/network/query.rs | 2 - core/src/network/reducers/get_links_count.rs | 37 +----------- core/src/network/reducers/mod.rs | 3 +- core/src/network/state.rs | 5 +- 8 files changed, 4 insertions(+), 179 deletions(-) diff --git a/core/src/action.rs b/core/src/action.rs index 02a3e31599..90995ef4bc 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -159,7 +159,6 @@ pub enum Action { GetLinksTimeout(GetLinksKey), GetLinksTimeoutByTag(GetLinksKeyByTag), GetLinksCount((GetLinksKey, Option)), - GetLinksCountByTag((GetLinksKeyByTag, Option)), RespondGetLinks((QueryEntryData, Vec<(Address, CrudStatus)>, String, String)), RespondGetLinksCount((QueryEntryData, usize, String, String)), RespondGetLinksCountByTag((QueryEntryData, usize, String)), @@ -264,17 +263,6 @@ pub struct GetLinksKey { pub id: String, } -/// The unique key that represents a GetLinksCountByTag request, used to associate the eventual -/// response with this GetLinks request -#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)] -pub struct GetLinksKeyByTag { - /// The link tag, None means get all the tags for a given type - pub tag: String, - - /// A unique ID that is used to pair the eventual result to this request - pub id: String, -} - /// The unique key that represents a Get request, used to associate the eventual /// response with this Get request #[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)] diff --git a/core/src/dht/dht_store.rs b/core/src/dht/dht_store.rs index ddc0054c1d..49d966b2aa 100644 --- a/core/src/dht/dht_store.rs +++ b/core/src/dht/dht_store.rs @@ -71,31 +71,9 @@ pub fn create_get_links_eavi_query<'a>( )) } -pub fn create_get_links_by_tag_eavi_query<'a>( - tag: String, -) -> Result, HolochainError> { let tag_regex = Regex::new(&tag).map_err(|_| HolochainError::from("Invalid regex passed for tag"))?; let tombstone_tag_regex = tag_regex.clone(); - Ok(EaviQuery::new( - None.into(), - EavFilter::predicate(move |attr: Attribute| match attr.clone() { - Attribute::LinkTag(_, query_tag) | Attribute::RemovedLink(_, query_tag) => { - tag_regex.is_match(&query_tag) - } - _ => false, - }), - None.into(), - IndexFilter::LatestByAttribute, - Some(EavFilter::predicate(move |attr: Attribute| { - match attr.clone() { - Attribute::RemovedLink(_, query_tag) => tombstone_tag_regex.is_match(&query_tag), - _ => false, - } - })), - )) -} - impl DhtStore { // LifeCycle // ========= @@ -132,23 +110,6 @@ impl DhtStore { .collect()) } - pub fn get_links_by_tag( - &self, - tag: String, - crud_filter: Option, - ) -> Result, HolochainError> { - let get_links_query = create_get_links_by_tag_eavi_query(tag)?; - let filtered = self.meta_storage.read()?.fetch_eavi(&get_links_query)?; - Ok(filtered - .into_iter() - .map(|s| match s.attribute() { - Attribute::LinkTag(_, _) => (s, CrudStatus::Live), - _ => (s, CrudStatus::Deleted), - }) - .filter(|link_crud| crud_filter.map(|crud| crud == link_crud.1).unwrap_or(true)) - .collect()) - } - pub fn get_all_metas( &self, address: &Address, diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs index 9dfe40dd53..d1c4898138 100644 --- a/core/src/network/actions/get_links_count.rs +++ b/core/src/network/actions/get_links_count.rs @@ -1,5 +1,5 @@ use crate::{ - action::{Action, ActionWrapper, GetLinksKey, GetLinksKeyByTag}, + action::{Action, ActionWrapper, GetLinksKey}, context::Context, instance::dispatch_action, }; @@ -53,38 +53,6 @@ pub async fn get_links_count( }) } -pub async fn get_links_count_by_tag( - context: Arc, - tag: String, - timeout: Timeout, - link_status_request: LinksStatusRequestKind, -) -> HcResult { - let key = GetLinksKeyByTag { - tag: tag.clone(), - id: ProcessUniqueId::new().to_string(), - }; - - let crud_status = match link_status_request { - LinksStatusRequestKind::All => None, - LinksStatusRequestKind::Live => Some(CrudStatus::Live), - LinksStatusRequestKind::Deleted => Some(CrudStatus::Deleted), - }; - let action_wrapper = ActionWrapper::new(Action::GetLinksCountByTag((key.clone(), crud_status))); - dispatch_action(context.action_channel(), action_wrapper.clone()); - - let key_inner = key.clone(); - let context_inner = context.clone(); - let _ = thread::spawn(move || { - thread::sleep(timeout.into()); - let action_wrapper = ActionWrapper::new(Action::GetLinksTimeoutByTag(key_inner)); - dispatch_action(context_inner.action_channel(), action_wrapper.clone()); - }); - - await!(GetLinksCountByTagFuture { - context: context.clone(), - key - }) -} /// GetLinksFuture resolves to a HcResult>. /// Tracks the state of the network module @@ -112,30 +80,3 @@ impl Future for GetLinksCountFuture { } } } - -/// GetLinksFuture resolves to a HcResult>. -/// Tracks the state of the network module -pub struct GetLinksCountByTagFuture { - context: Arc, - key: GetLinksKeyByTag, -} - -impl Future for GetLinksCountByTagFuture { - type Output = HcResult; - - fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - let state = self.context.state().unwrap().network(); - if let Err(error) = state.initialized() { - return Poll::Ready(Err(error)); - } - // - // TODO: connect the waker to state updates for performance reasons - // See: https://github.com/holochain/holochain-rust/issues/314 - // - lw.wake(); - match state.get_links_result_count_by_tag.get(&self.key) { - Some(Some(result)) => Poll::Ready(result.clone()), - _ => Poll::Pending, - } - } -} diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index ee08864957..83da8f58dc 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -30,22 +30,6 @@ fn get_links( .collect::>() } -fn get_links_by_tag( - context: &Arc, - tag: String, - crud_status: Option, -) -> Vec<(Address, CrudStatus)> { - context - .state() - .unwrap() - .dht() - .get_links_by_tag(tag, crud_status) - .unwrap_or(BTreeSet::new()) - .into_iter() - .map(|eav_crud| (eav_crud.0.value(), eav_crud.1)) - .collect::>() -} - fn get_entry(context: &Arc, address: Address) -> Option { nucleus::actions::get_entry::get_entry_with_meta(&context, address.clone()) .map(|entry_with_meta_opt| { @@ -117,14 +101,6 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc tag.clone(), ))) } - Ok(NetworkQuery::GetLinksByTag(tag, crud)) => { - let links_count = get_links_by_tag(&context, tag.clone(), crud.clone()).len(); - ActionWrapper::new(Action::RespondGetLinksCountByTag(( - query_data, - links_count, - tag.clone(), - ))) - } Ok(NetworkQuery::GetEntry) => { let maybe_entry = get_entry(&context, query_data.entry_address.clone()); ActionWrapper::new(Action::RespondGet((query_data, maybe_entry))) diff --git a/core/src/network/query.rs b/core/src/network/query.rs index 561e07013c..cc4545c4b8 100644 --- a/core/src/network/query.rs +++ b/core/src/network/query.rs @@ -7,7 +7,6 @@ pub enum NetworkQuery { GetEntry, GetLinks(String, String), GetLinksCount(String, String, Option), - GetLinksByTag(String, Option), } #[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] @@ -15,5 +14,4 @@ pub enum NetworkQueryResult { Entry(Option), Links(Vec<(Address, CrudStatus)>, String, String), LinksCount(usize, String, String), - LinksCountByTag(usize, String), } diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs index c3e0de579d..498410c43c 100644 --- a/core/src/network/reducers/get_links_count.rs +++ b/core/src/network/reducers/get_links_count.rs @@ -1,5 +1,5 @@ use crate::{ - action::{ActionWrapper, GetLinksKey, GetLinksKeyByTag}, + action::{ActionWrapper, GetLinksKey}, network::{query::NetworkQuery, reducers::send, state::NetworkState}, state::State, }; @@ -29,25 +29,6 @@ fn reduce_get_links_inner( ) } -fn reduce_get_links_inner_by_tag( - network_state: &mut NetworkState, - key: &GetLinksKeyByTag, - crud_status: Option, -) -> Result<(), HolochainError> { - network_state.initialized()?; - let query_json: JsonString = NetworkQuery::GetLinksByTag(key.tag.clone(), crud_status).into(); - send( - network_state, - JsonProtocol::QueryEntry(QueryEntryData { - requester_agent_id: network_state.agent_id.clone().unwrap().into(), - request_id: key.id.clone(), - dna_address: network_state.dna_address.clone().unwrap(), - entry_address: HashString::from(String::default()), - query: query_json.to_string().into_bytes(), - }), - ) -} - pub fn reduce_get_links_count( network_state: &mut NetworkState, _root_state: &State, @@ -64,22 +45,6 @@ pub fn reduce_get_links_count( network_state .get_links_results_count .insert(key.clone(), result); -} - -pub fn reduce_get_links_count_by_tag( - network_state: &mut NetworkState, - _root_state: &State, - action_wrapper: &ActionWrapper, -) { - let action = action_wrapper.action(); - let (key, crud) = unwrap_to!(action => crate::action::Action::GetLinksCountByTag); - - let result = match reduce_get_links_inner_by_tag(network_state, &key, crud.clone()) { - Ok(()) => None, - Err(err) => Some(Err(err)), - }; - - network_state .get_links_result_count_by_tag .insert(key.clone(), result); } diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index 9c23c69323..a375946a92 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -23,7 +23,7 @@ use crate::{ reducers::{ get_entry::{reduce_get_entry, reduce_get_entry_timeout}, get_links::{reduce_get_links, reduce_get_links_timeout}, - get_links_count::{ + get_links_count::reduce_get_links_count, reduce_get_links_count, reduce_get_links_count_by_tag, reduce_get_links_timeout_by_tag, }, @@ -67,7 +67,6 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::GetEntryTimeout(_) => Some(reduce_get_entry_timeout), Action::GetLinks(_) => Some(reduce_get_links), Action::GetLinksCount(_) => Some(reduce_get_links_count), - Action::GetLinksCountByTag(_) => Some(reduce_get_links_count_by_tag), Action::GetLinksTimeout(_) => Some(reduce_get_links_timeout), Action::GetLinksTimeoutByTag(_) => Some(reduce_get_links_timeout_by_tag), Action::GetValidationPackage(_) => Some(reduce_get_validation_package), diff --git a/core/src/network/state.rs b/core/src/network/state.rs index 36485d37e6..2fb4f08548 100644 --- a/core/src/network/state.rs +++ b/core/src/network/state.rs @@ -1,5 +1,5 @@ use crate::{ - action::{ActionWrapper, GetEntryKey, GetLinksKey, GetLinksKeyByTag}, + action::{ActionWrapper, GetEntryKey, GetLinksKey}, network::{actions::ActionResponse, direct_message::DirectMessage}, }; use boolinator::*; @@ -63,8 +63,6 @@ pub struct NetworkState { pub get_links_results_count: HashMap, - pub get_links_result_count_by_tag: HashMap, - /// Here we store the results of get validation package processes. /// None means that we are still waiting for a result from the network. pub get_validation_package_results: HashMap, @@ -95,7 +93,6 @@ impl NetworkState { get_entry_with_meta_results: HashMap::new(), get_links_results: HashMap::new(), get_links_results_count: HashMap::new(), - get_links_result_count_by_tag: HashMap::new(), get_validation_package_results: HashMap::new(), direct_message_connections: HashMap::new(), custom_direct_message_replys: HashMap::new(), From ba7fbb8c4055ef3aed11ec9175af231ebf7b80cb Mon Sep 17 00:00:00 2001 From: Purple Hair Rust Bard Date: Fri, 5 Jul 2019 20:06:31 -0400 Subject: [PATCH 31/48] revert more tag issues --- core/src/action.rs | 2 +- core/src/dht/dht_store.rs | 4 +--- core/src/network/actions/get_links_count.rs | 1 + core/src/network/handler/query.rs | 16 ++++++---------- core/src/network/reducers/get_links_count.rs | 1 + .../reducers/handle_get_links_result_count.rs | 13 ------------- core/src/network/reducers/mod.rs | 6 +----- core/src/nucleus/ribosome/api/get_links_count.rs | 2 +- core/src/workflows/get_links_count.rs | 14 ++++++++------ hdk-rust/src/api/get_links.rs | 9 +++++---- hdk-rust/src/api/mod.rs | 4 ++-- wasm_utils/src/api_serialization/get_links.rs | 5 +++-- 12 files changed, 30 insertions(+), 47 deletions(-) diff --git a/core/src/action.rs b/core/src/action.rs index 90995ef4bc..85bf1a3fbd 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -164,7 +164,6 @@ pub enum Action { RespondGetLinksCountByTag((QueryEntryData, usize, String)), HandleGetLinksResult((Vec<(Address, CrudStatus)>, GetLinksKey)), HandleGetLinksResultCount((usize, GetLinksKey)), - HandleGetLinksResultCountByTag((usize, GetLinksKeyByTag)), /// Makes the network module send a direct (node-to-node) message /// to the address given in [DirectMessageData](struct.DirectMessageData.html) @@ -263,6 +262,7 @@ pub struct GetLinksKey { pub id: String, } + /// The unique key that represents a Get request, used to associate the eventual /// response with this Get request #[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)] diff --git a/core/src/dht/dht_store.rs b/core/src/dht/dht_store.rs index 49d966b2aa..54b7f74c32 100644 --- a/core/src/dht/dht_store.rs +++ b/core/src/dht/dht_store.rs @@ -71,9 +71,7 @@ pub fn create_get_links_eavi_query<'a>( )) } - let tag_regex = - Regex::new(&tag).map_err(|_| HolochainError::from("Invalid regex passed for tag"))?; - let tombstone_tag_regex = tag_regex.clone(); + impl DhtStore { // LifeCycle // ========= diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs index d1c4898138..6511dcb2e6 100644 --- a/core/src/network/actions/get_links_count.rs +++ b/core/src/network/actions/get_links_count.rs @@ -54,6 +54,7 @@ pub async fn get_links_count( } + /// GetLinksFuture resolves to a HcResult>. /// Tracks the state of the network module pub struct GetLinksCountFuture { diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index 83da8f58dc..2e7d5da728 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -1,5 +1,5 @@ use crate::{ - action::{Action, ActionWrapper, GetEntryKey, GetLinksKey, GetLinksKeyByTag}, + action::{Action, ActionWrapper, GetEntryKey, GetLinksKey}, context::Context, entry::CanPublish, instance::dispatch_action, @@ -100,6 +100,11 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc link_type.clone(), tag.clone(), ))) + &context, + tag.clone(), + crud.clone(), + ) + .len(); } Ok(NetworkQuery::GetEntry) => { let maybe_entry = get_entry(&context, query_data.entry_address.clone()); @@ -153,15 +158,6 @@ pub fn handle_query_entry_result(query_result_data: QueryEntryResultData, contex }, ))) } - Ok(NetworkQueryResult::LinksCountByTag(links_count, tag)) => { - ActionWrapper::new(Action::HandleGetLinksResultCountByTag(( - links_count, - GetLinksKeyByTag { - tag: tag.clone(), - id: query_result_data.request_id.clone(), - }, - ))) - } err => { context.log(format!( "err/net: Error ({:?}) deserializing QueryResult {:?}", diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs index 498410c43c..bfc0ccb4b8 100644 --- a/core/src/network/reducers/get_links_count.rs +++ b/core/src/network/reducers/get_links_count.rs @@ -29,6 +29,7 @@ fn reduce_get_links_inner( ) } + NetworkQuery::GetLinksByTag(key.tag.clone(), crud_status).into(); pub fn reduce_get_links_count( network_state: &mut NetworkState, _root_state: &State, diff --git a/core/src/network/reducers/handle_get_links_result_count.rs b/core/src/network/reducers/handle_get_links_result_count.rs index b8e73df77a..bd17ad343b 100644 --- a/core/src/network/reducers/handle_get_links_result_count.rs +++ b/core/src/network/reducers/handle_get_links_result_count.rs @@ -11,16 +11,3 @@ pub fn reduce_handle_get_links_count( .get_links_results_count .insert(key.clone(), Some(Ok(links_count.clone()))); } - -pub fn reduce_handle_get_links_count_by_tag( - network_state: &mut NetworkState, - _root_state: &State, - action_wrapper: &ActionWrapper, -) { - let action = action_wrapper.action(); - let (links_count, key) = - unwrap_to!(action => crate::action::Action::HandleGetLinksResultCountByTag); - network_state - .get_links_result_count_by_tag - .insert(key.clone(), Some(Ok(links_count.clone()))); -} diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index a375946a92..9ba20db8c5 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -30,9 +30,7 @@ use crate::{ get_validation_package::reduce_get_validation_package, handle_custom_send_response::reduce_handle_custom_send_response, handle_get_links_result::reduce_handle_get_links_result, - handle_get_links_result_count::{ - reduce_handle_get_links_count, reduce_handle_get_links_count_by_tag, - }, + handle_get_links_result_count::reduce_handle_get_links_count, handle_get_result::reduce_handle_get_result, handle_get_validation_package::reduce_handle_get_validation_package, init::reduce_init, @@ -68,14 +66,12 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::GetLinks(_) => Some(reduce_get_links), Action::GetLinksCount(_) => Some(reduce_get_links_count), Action::GetLinksTimeout(_) => Some(reduce_get_links_timeout), - Action::GetLinksTimeoutByTag(_) => Some(reduce_get_links_timeout_by_tag), Action::GetValidationPackage(_) => Some(reduce_get_validation_package), Action::HandleCustomSendResponse(_) => Some(reduce_handle_custom_send_response), Action::HandleGetResult(_) => Some(reduce_handle_get_result), Action::HandleGetLinksResult(_) => Some(reduce_handle_get_links_result), Action::HandleGetValidationPackage(_) => Some(reduce_handle_get_validation_package), Action::HandleGetLinksResultCount(_) => Some(reduce_handle_get_links_count), - Action::HandleGetLinksResultCountByTag(_) => Some(reduce_handle_get_links_count_by_tag), Action::InitNetwork(_) => Some(reduce_init), Action::Publish(_) => Some(reduce_publish), Action::ResolveDirectConnection(_) => Some(reduce_resolve_direct_connection), diff --git a/core/src/nucleus/ribosome/api/get_links_count.rs b/core/src/nucleus/ribosome/api/get_links_count.rs index 9622cb54ba..ca412dcd6b 100644 --- a/core/src/nucleus/ribosome/api/get_links_count.rs +++ b/core/src/nucleus/ribosome/api/get_links_count.rs @@ -10,7 +10,7 @@ pub fn invoke_get_links_count(runtime: &mut Runtime, args: &RuntimeArgs) -> Zome let context = runtime.context()?; // deserialize args let args_str = runtime.load_json_string_from_args(&args); - + let input = match GetLinksBy::try_from(args_str.clone()) { Ok(input) => { context.log(format!( diff --git a/core/src/workflows/get_links_count.rs b/core/src/workflows/get_links_count.rs index 79b1066d3f..637eea6ebf 100644 --- a/core/src/workflows/get_links_count.rs +++ b/core/src/workflows/get_links_count.rs @@ -4,22 +4,24 @@ use crate::{ }; use holochain_core_types::error::HolochainError; -use holochain_wasm_utils::api_serialization::get_links::{GetLinksBy, GetLinksResultCount}; +use holochain_wasm_utils::api_serialization::get_links::{ GetLinksResultCount,GetLinksBy}; use std::sync::Arc; pub async fn get_link_result_count_workflow<'a>( context: Arc, link_args: &'a GetLinksBy, ) -> Result { - let links_count = match link_args { - GetLinksBy::GetLinksArgs(link_args) => await!(get_links_count( - context, + let links_count = match link_args + { + GetLinksBy::GetLinksArgs(link_args)=> + { + await!(get_links_count(context, link_args.entry_address.clone(), link_args.link_type.clone(), link_args.tag.clone(), link_args.options.timeout.clone(), - link_args.options.status_request.clone() - ))?, + link_args.options.status_request.clone()))? + }, GetLinksBy::Tag(tag, options) => await!(get_links_count_by_tag( context, tag.to_string(), diff --git a/hdk-rust/src/api/get_links.rs b/hdk-rust/src/api/get_links.rs index 2a361acdb2..93a352133a 100644 --- a/hdk-rust/src/api/get_links.rs +++ b/hdk-rust/src/api/get_links.rs @@ -5,7 +5,7 @@ use holochain_core_types::{entry::Entry, link::LinkMatch}; use holochain_persistence_api::{cas::content::Address, hash::HashString}; use holochain_wasm_utils::api_serialization::{ get_entry::{GetEntryOptions, GetEntryResult, GetEntryResultItem, GetEntryResultType}, - get_links::{GetLinksArgs, GetLinksBy, GetLinksOptions, GetLinksResult, GetLinksResultCount}, + get_links::{GetLinksArgs, GetLinksOptions, GetLinksResult, GetLinksResultCount,GetLinksBy}, }; /// Consumes four values; the address of an entry get get links from (the base), the type of the links @@ -99,15 +99,16 @@ pub fn get_links_count( get_links_count_with_options(base, link_type, tag, GetLinksOptions::default()) } -pub fn get_links_count_by_tag( +pub fn get_links_by_tag( tag: LinkMatch<&str>, - options: GetLinksOptions, + options : GetLinksOptions ) -> ZomeApiResult { let tag_re = tag.to_regex_string()?; - let get_links_args = GetLinksBy::Tag(tag_re, options); + let get_links_args = GetLinksBy::Tag(tag_re,options); Dispatch::GetLinksCount.with_input(get_links_args) } + /// Helper function for get_links. Returns a vector with the default return results. pub fn get_links( base: &Address, diff --git a/hdk-rust/src/api/mod.rs b/hdk-rust/src/api/mod.rs index 7d10ba0a53..942e61539b 100644 --- a/hdk-rust/src/api/mod.rs +++ b/hdk-rust/src/api/mod.rs @@ -53,8 +53,8 @@ pub use self::{ entry_type_properties::entry_type_properties, get_entry::{get_entry, get_entry_history, get_entry_initial, get_entry_result}, get_links::{ - get_links, get_links_and_load, get_links_count, get_links_count_by_tag, - get_links_count_with_options, get_links_result, get_links_with_options, + get_links, get_links_and_load, get_links_count, get_links_count_with_options, + get_links_result, get_links_with_options, }, keystore::{ keystore_derive_key, keystore_derive_seed, keystore_get_public_key, keystore_list, diff --git a/wasm_utils/src/api_serialization/get_links.rs b/wasm_utils/src/api_serialization/get_links.rs index 4ac6bc03b6..94cb90f170 100644 --- a/wasm_utils/src/api_serialization/get_links.rs +++ b/wasm_utils/src/api_serialization/get_links.rs @@ -52,9 +52,10 @@ pub struct GetLinksResult { } #[derive(Deserialize, Debug, Serialize, DefaultJson, Clone, PartialEq, Hash, Eq)] -pub enum GetLinksBy { +pub enum GetLinksBy +{ GetLinksArgs(GetLinksArgs), - Tag(String, GetLinksOptions), + Tag(String,GetLinksOptions) } #[derive(Deserialize, Serialize, Debug, DefaultJson)] From e91ab6c8cd98532b92257d44dd483cc268a6d768 Mon Sep 17 00:00:00 2001 From: Purple Hair Rust Bard Date: Fri, 5 Jul 2019 20:16:14 -0400 Subject: [PATCH 32/48] reverted app_spec test --- app_spec/test/test.js | 69 ------------------- app_spec/zomes/simple/code/src/lib.rs | 36 ---------- .../zomes/simple/code/src/lib.rs | 7 -- core/src/network/reducers/get_links_count.rs | 28 -------- 4 files changed, 140 deletions(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index ba3433aabd..8ab7a40af8 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -914,75 +914,6 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { }) -scenario('get_links_crud_count_tag', async (s, t, { alice, bob }) => { - - //commits an entry and creates two links for alice - await alice.app.callSync("simple", "create_link_with_tag", - { "base": alice.app.agentId ,"target": "Holo world","tag":"tag1" } - ); - - const alice_result = await alice.app.callSync("simple", "create_link_with_tag", - { "base": bob.app.agentId ,"target": "Holo world 2","tag":"tag1" } - ); - - //get posts for alice from alice - const alice_posts_live= await alice.app.call("simple","get_my_links_count_by_tag", - { - "tag" : "tag1","status_request":"Live" - }) - - //get posts for alice from bob - const bob_posts_live= await alice.app.call("simple","get_my_links_count_by_tag", - { - "tag" : "tag1","status_request":"Live" - }) - - //make sure count equals to 2 - t.equal(2,alice_posts_live.Ok.count); - t.equal(2,bob_posts_live.Ok.count); - - //delete link - let deleted_link = await alice.app.callSync("simple","delete_link_with_tag", - { - "base" : alice.app.agentId, - "target" : "Holo world", - "tag" : "tag1" - }); - - - //get posts for alice from alice - const alice_posts_deleted= await alice.app.call("simple","get_my_links_count_by_tag", - { - "tag" : "tag1","status_request":"Deleted" - }) - - //get posts for alice from bob - const bob_posts_deleted= await alice.app.call("simple","get_my_links_count_by_tag", - { - "tag" : "tag1","status_request":"Deleted" - }) - - t.equal(1,alice_posts_deleted.Ok.count); - t.equal(1,bob_posts_deleted.Ok.count); - - - const alice_posts_all= await alice.app.call("simple","get_my_links_count_by_tag", - { - "tag" : "tag1","status_request":"All" - }) - - //get posts for alice from bob - const bob_posts_all= await alice.app.call("simple","get_my_links_count_by_tag", - { - "tag" : "tag1","status_request":"All" - }) - - t.equal(2,alice_posts_all.Ok.count); - t.equal(2,bob_posts_all.Ok.count); - - - -}) scenario('create/get_post roundtrip', async (s, t, { alice }) => { const content = "Holo world" diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index 3d550ef8f4..d2e532f134 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -58,24 +58,12 @@ pub fn handle_create_my_link(base: Address,target : String) -> ZomeApiResult<()> Ok(()) } -pub fn handle_create_my_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()> { - let address = hdk::commit_entry(&simple_entry(target))?; - hdk::link_entries(&base, &HashString::from(address), "authored_simple_posts", &tag)?; - Ok(()) -} - pub fn handle_delete_my_link(base: Address,target : String) -> ZomeApiResult<()> { let address = hdk::entry_address(&simple_entry(target))?; hdk::remove_link(&base, &HashString::from(address), "authored_simple_posts", "")?; Ok(()) } -pub fn handle_delete_my_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()> { - let address = hdk::entry_address(&simple_entry(target))?; - hdk::remove_link(&base, &HashString::from(address), "authored_simple_posts", &tag)?; - Ok(()) -} - pub fn handle_get_my_links(agent : Address,status_request:Option) ->ZomeApiResult { @@ -95,15 +83,6 @@ pub fn handle_get_my_links_count(agent : Address,status_request:Option) ->ZomeApiResult -{ - let options = GetLinksOptions{ - status_request : status_request.unwrap_or(LinksStatusRequestKind::All), - ..GetLinksOptions::default() - }; - hdk::get_links_count_by_tag(LinkMatch::Exactly(&tag),options) -} - pub fn handle_test_emit_signal(message: String) -> ZomeApiResult<()> { #[derive(Debug, Serialize, Deserialize, DefaultJson)] struct SignalPayload { @@ -170,21 +149,11 @@ define_zome! { outputs: |result: ZomeApiResult<()>|, handler: handle_create_my_link } - create_link_with_tag: { - inputs: |base : Address,target:String,tag:String|, - outputs: |result: ZomeApiResult<()>|, - handler: handle_create_my_link_with_tag - } delete_link: { inputs: |base : Address,target:String|, outputs: |result: ZomeApiResult<()>|, handler: handle_delete_my_link } - delete_link_with_tag: { - inputs: |base : Address,target:String,tag:String|, - outputs: |result: ZomeApiResult<()>|, - handler: handle_delete_my_link_with_tag - } get_my_links: { inputs: |base: Address,status_request:Option|, outputs: |result: ZomeApiResult|, @@ -195,11 +164,6 @@ define_zome! { outputs: |result: ZomeApiResult|, handler: handle_get_my_links_count } - get_my_links_count_by_tag: { - inputs: |tag: String,status_request:Option|, - outputs: |result: ZomeApiResult|, - handler: handle_get_my_links_by_tag_count - } encrypt :{ inputs : |payload: String|, outputs: |result: ZomeApiResult|, diff --git a/app_spec_proc_macro/zomes/simple/code/src/lib.rs b/app_spec_proc_macro/zomes/simple/code/src/lib.rs index dbe4220bdc..f072b722e2 100644 --- a/app_spec_proc_macro/zomes/simple/code/src/lib.rs +++ b/app_spec_proc_macro/zomes/simple/code/src/lib.rs @@ -122,13 +122,6 @@ pub mod simple { Ok(()) } - #[zome_fn("hc_public")] - pub fn delete_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()> { - let address = hdk::entry_address(&simple_entry(target))?; - hdk::remove_link(&base, &address, "authored_simple_posts", &tag)?; - Ok(()) - } - #[zome_fn("hc_public")] pub fn get_my_links(base: Address,status_request : Option) -> ZomeApiResult { diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs index bfc0ccb4b8..cd14ac7129 100644 --- a/core/src/network/reducers/get_links_count.rs +++ b/core/src/network/reducers/get_links_count.rs @@ -28,8 +28,6 @@ fn reduce_get_links_inner( }), ) } - - NetworkQuery::GetLinksByTag(key.tag.clone(), crud_status).into(); pub fn reduce_get_links_count( network_state: &mut NetworkState, _root_state: &State, @@ -69,30 +67,4 @@ pub fn reduce_get_links_timeout( } } -pub fn reduce_get_links_timeout_by_tag( - network_state: &mut NetworkState, - _root_state: &State, - action_wrapper: &ActionWrapper, -) { - let action = action_wrapper.action(); - let key = unwrap_to!(action => crate::action::Action::GetLinksTimeoutByTag); - if network_state - .get_links_result_count_by_tag - .get(key) - .is_none() - { - return; - } - - if network_state - .get_links_result_count_by_tag - .get(key) - .unwrap() - .is_none() - { - network_state - .get_links_result_count_by_tag - .insert(key.clone(), Some(Err(HolochainError::Timeout))); - } -} From 51eb5a563f07ba6ee289c89abaa836e4cea3955b Mon Sep 17 00:00:00 2001 From: Purple Hair Rust Bard Date: Fri, 5 Jul 2019 20:47:29 -0400 Subject: [PATCH 33/48] cargo fmt after revert --- CHANGELOG-UNRELEASED.md | 2 +- .../zomes/simple/code/src/lib.rs | 10 ---- core/src/action.rs | 3 -- core/src/dht/dht_store.rs | 1 - core/src/network/actions/get_links_count.rs | 2 - core/src/network/handler/query.rs | 5 -- core/src/network/reducers/get_links_count.rs | 23 --------- core/src/network/reducers/mod.rs | 8 +--- .../reducers/respond_get_links_count.rs | 48 ------------------- .../nucleus/ribosome/api/get_links_count.rs | 6 +-- core/src/workflows/get_links_count.rs | 36 +++++--------- hdk-rust/src/api/get_links.rs | 18 ++----- wasm_utils/src/api_serialization/get_links.rs | 7 --- 13 files changed, 19 insertions(+), 150 deletions(-) diff --git a/CHANGELOG-UNRELEASED.md b/CHANGELOG-UNRELEASED.md index d1bcc90417..d42391fba1 100644 --- a/CHANGELOG-UNRELEASED.md +++ b/CHANGELOG-UNRELEASED.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `Encryption` and `Decryption` methods in the HDK [#1534](https://github.com/holochain/holochain-rust/pull/1534) - Adds `hc hash` CLI subcommand. Can be used to compute the hash of the DNA in the current dist directory or passed a path to a DNA with the --path flag [#1562](https://github.com/holochain/holochain-rust/pull/1562) - Adds a --dna flag to the CLI so `hc run` can run DNAs outside the standard ./dist/ directory [1561](https://github.com/holochain/holochain-rust/pull/1561) -- Added a `get_links_count` and `get_links_count_by_tag` method which allows the user to get number of links by base , target or just by the tag. [#1568](https://github.com/holochain/holochain-rust/pull/1568) +- Added a `get_links_count` method which allows the user to get number of links by base and tag [#1568](https://github.com/holochain/holochain-rust/pull/1568) ### Changed diff --git a/app_spec_proc_macro/zomes/simple/code/src/lib.rs b/app_spec_proc_macro/zomes/simple/code/src/lib.rs index f072b722e2..9284c69616 100644 --- a/app_spec_proc_macro/zomes/simple/code/src/lib.rs +++ b/app_spec_proc_macro/zomes/simple/code/src/lib.rs @@ -142,16 +142,6 @@ pub mod simple { hdk::get_links_count_with_options(&base, LinkMatch::Exactly("authored_simple_posts"), LinkMatch::Any,options) } - #[zome_fn("hc_public")] - pub fn get_my_links_count_by_tag(tag : String,status_request:Option) ->ZomeApiResult - { - let options = GetLinksOptions{ - status_request : status_request.unwrap_or(LinksStatusRequestKind::All), - ..GetLinksOptions::default() - }; - hdk::get_links_count_by_tag(LinkMatch::Exactly(&tag),options) - } - #[zome_fn("hc_public")] pub fn test_emit_signal(message: String) -> ZomeApiResult<()> { #[derive(Debug, Serialize, Deserialize, DefaultJson)] diff --git a/core/src/action.rs b/core/src/action.rs index 85bf1a3fbd..3f008edbd3 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -157,11 +157,9 @@ pub enum Action { /// Last string is the stringified process unique id of this `hdk::get_links` call. GetLinks(GetLinksKey), GetLinksTimeout(GetLinksKey), - GetLinksTimeoutByTag(GetLinksKeyByTag), GetLinksCount((GetLinksKey, Option)), RespondGetLinks((QueryEntryData, Vec<(Address, CrudStatus)>, String, String)), RespondGetLinksCount((QueryEntryData, usize, String, String)), - RespondGetLinksCountByTag((QueryEntryData, usize, String)), HandleGetLinksResult((Vec<(Address, CrudStatus)>, GetLinksKey)), HandleGetLinksResultCount((usize, GetLinksKey)), @@ -262,7 +260,6 @@ pub struct GetLinksKey { pub id: String, } - /// The unique key that represents a Get request, used to associate the eventual /// response with this Get request #[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)] diff --git a/core/src/dht/dht_store.rs b/core/src/dht/dht_store.rs index 54b7f74c32..816d2acaa2 100644 --- a/core/src/dht/dht_store.rs +++ b/core/src/dht/dht_store.rs @@ -71,7 +71,6 @@ pub fn create_get_links_eavi_query<'a>( )) } - impl DhtStore { // LifeCycle // ========= diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs index 6511dcb2e6..45f3ab76b8 100644 --- a/core/src/network/actions/get_links_count.rs +++ b/core/src/network/actions/get_links_count.rs @@ -53,8 +53,6 @@ pub async fn get_links_count( }) } - - /// GetLinksFuture resolves to a HcResult>. /// Tracks the state of the network module pub struct GetLinksCountFuture { diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index 2e7d5da728..a6f3e7a412 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -100,11 +100,6 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc link_type.clone(), tag.clone(), ))) - &context, - tag.clone(), - crud.clone(), - ) - .len(); } Ok(NetworkQuery::GetEntry) => { let maybe_entry = get_entry(&context, query_data.entry_address.clone()); diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs index cd14ac7129..efff98f9a6 100644 --- a/core/src/network/reducers/get_links_count.rs +++ b/core/src/network/reducers/get_links_count.rs @@ -44,27 +44,4 @@ pub fn reduce_get_links_count( network_state .get_links_results_count .insert(key.clone(), result); - .get_links_result_count_by_tag - .insert(key.clone(), result); -} - -pub fn reduce_get_links_timeout( - network_state: &mut NetworkState, - _root_state: &State, - action_wrapper: &ActionWrapper, -) { - let action = action_wrapper.action(); - let key = unwrap_to!(action => crate::action::Action::GetLinksTimeout); - - if network_state.get_links_results.get(key).is_none() { - return; - } - - if network_state.get_links_results.get(key).unwrap().is_none() { - network_state - .get_links_results - .insert(key.clone(), Some(Err(HolochainError::Timeout))); - } } - - diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index 9ba20db8c5..f75ed611a1 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -24,9 +24,6 @@ use crate::{ get_entry::{reduce_get_entry, reduce_get_entry_timeout}, get_links::{reduce_get_links, reduce_get_links_timeout}, get_links_count::reduce_get_links_count, - reduce_get_links_count, reduce_get_links_count_by_tag, - reduce_get_links_timeout_by_tag, - }, get_validation_package::reduce_get_validation_package, handle_custom_send_response::reduce_handle_custom_send_response, handle_get_links_result::reduce_handle_get_links_result, @@ -39,9 +36,7 @@ use crate::{ respond_fetch::reduce_respond_fetch_data, respond_get::reduce_respond_get, respond_get_links::reduce_respond_get_links, - respond_get_links_count::{ - reduce_respond_get_links_count, reduce_respond_get_links_count_by_tag, - }, + respond_get_links_count::reduce_respond_get_links_count, send_direct_message::{reduce_send_direct_message, reduce_send_direct_message_timeout}, }, state::NetworkState, @@ -79,7 +74,6 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::RespondGet(_) => Some(reduce_respond_get), Action::RespondGetLinks(_) => Some(reduce_respond_get_links), Action::RespondGetLinksCount(_) => Some(reduce_respond_get_links_count), - Action::RespondGetLinksCountByTag(_) => Some(reduce_respond_get_links_count_by_tag), Action::SendDirectMessage(_) => Some(reduce_send_direct_message), Action::SendDirectMessageTimeout(_) => Some(reduce_send_direct_message_timeout), _ => None, diff --git a/core/src/network/reducers/respond_get_links_count.rs b/core/src/network/reducers/respond_get_links_count.rs index 7155a76321..df0664ac1f 100644 --- a/core/src/network/reducers/respond_get_links_count.rs +++ b/core/src/network/reducers/respond_get_links_count.rs @@ -36,30 +36,6 @@ fn reduce_respond_get_links_count_inner( ) } -/// Send back to network a HandleQueryEntryResult, no matter what. -/// Will return an empty content field if it actually doesn't have the data. -fn reduce_respond_get_links_count_inner_by_tag( - network_state: &mut NetworkState, - query_data: &QueryEntryData, - links_count: usize, - tag: String, -) -> Result<(), HolochainError> { - network_state.initialized()?; - let query_result_json: JsonString = - NetworkQueryResult::LinksCountByTag(links_count.clone(), tag).into(); - send( - network_state, - JsonProtocol::HandleQueryEntryResult(QueryEntryResultData { - request_id: query_data.request_id.clone(), - requester_agent_id: query_data.requester_agent_id.clone(), - dna_address: network_state.dna_address.clone().unwrap(), - responder_agent_id: network_state.agent_id.clone().unwrap().into(), - entry_address: query_data.entry_address.clone().into(), - query_result: query_result_json.to_string().into_bytes(), - }), - ) -} - pub fn reduce_respond_get_links_count( network_state: &mut NetworkState, _root_state: &State, @@ -84,27 +60,3 @@ pub fn reduce_respond_get_links_count( }), ); } - -pub fn reduce_respond_get_links_count_by_tag( - network_state: &mut NetworkState, - _root_state: &State, - action_wrapper: &ActionWrapper, -) { - let action = action_wrapper.action(); - let (query_data, links_count, tag) = - unwrap_to!(action => crate::action::Action::RespondGetLinksCountByTag); - let result = reduce_respond_get_links_count_inner_by_tag( - network_state, - query_data, - links_count.clone(), - tag.clone(), - ); - - network_state.actions.insert( - action_wrapper.clone(), - ActionResponse::RespondGetLinksCount(match result { - Ok(_) => Ok(()), - Err(e) => Err(HolochainError::ErrorGeneric(e.to_string())), - }), - ); -} diff --git a/core/src/nucleus/ribosome/api/get_links_count.rs b/core/src/nucleus/ribosome/api/get_links_count.rs index ca412dcd6b..693d6c6203 100644 --- a/core/src/nucleus/ribosome/api/get_links_count.rs +++ b/core/src/nucleus/ribosome/api/get_links_count.rs @@ -2,7 +2,7 @@ use crate::{ nucleus::ribosome::{api::ZomeApiResult, Runtime}, workflows::get_links_count::get_link_result_count_workflow, }; -use holochain_wasm_utils::api_serialization::get_links::GetLinksBy; +use holochain_wasm_utils::api_serialization::get_links::GetLinksArgs; use std::convert::TryFrom; use wasmi::{RuntimeArgs, RuntimeValue}; @@ -10,8 +10,8 @@ pub fn invoke_get_links_count(runtime: &mut Runtime, args: &RuntimeArgs) -> Zome let context = runtime.context()?; // deserialize args let args_str = runtime.load_json_string_from_args(&args); - - let input = match GetLinksBy::try_from(args_str.clone()) { + + let input = match GetLinksArgs::try_from(args_str.clone()) { Ok(input) => { context.log(format!( "log/get_links: invoke_get_links called with {:?}", diff --git a/core/src/workflows/get_links_count.rs b/core/src/workflows/get_links_count.rs index 637eea6ebf..1819ceafd3 100644 --- a/core/src/workflows/get_links_count.rs +++ b/core/src/workflows/get_links_count.rs @@ -1,35 +1,21 @@ -use crate::{ - context::Context, - network::actions::get_links_count::{get_links_count, get_links_count_by_tag}, -}; +use crate::{context::Context, network::actions::get_links_count::get_links_count}; use holochain_core_types::error::HolochainError; -use holochain_wasm_utils::api_serialization::get_links::{ GetLinksResultCount,GetLinksBy}; +use holochain_wasm_utils::api_serialization::get_links::{GetLinksArgs, GetLinksResultCount}; use std::sync::Arc; pub async fn get_link_result_count_workflow<'a>( context: Arc, - link_args: &'a GetLinksBy, + link_args: &'a GetLinksArgs, ) -> Result { - let links_count = match link_args - { - GetLinksBy::GetLinksArgs(link_args)=> - { - await!(get_links_count(context, - link_args.entry_address.clone(), - link_args.link_type.clone(), - link_args.tag.clone(), - link_args.options.timeout.clone(), - link_args.options.status_request.clone()))? - }, - GetLinksBy::Tag(tag, options) => await!(get_links_count_by_tag( - context, - tag.to_string(), - options.timeout.clone(), - options.status_request.clone() - ))?, - }; - //get links based on status request, all for everything, deleted for deleted links and live for active links + let links_count = await!(get_links_count( + context, + link_args.entry_address.clone(), + link_args.link_type.clone(), + link_args.tag.clone(), + link_args.options.timeout.clone(), + link_args.options.status_request.clone() + ))?; Ok(GetLinksResultCount { count: links_count }) } diff --git a/hdk-rust/src/api/get_links.rs b/hdk-rust/src/api/get_links.rs index 93a352133a..743d570090 100644 --- a/hdk-rust/src/api/get_links.rs +++ b/hdk-rust/src/api/get_links.rs @@ -5,7 +5,7 @@ use holochain_core_types::{entry::Entry, link::LinkMatch}; use holochain_persistence_api::{cas::content::Address, hash::HashString}; use holochain_wasm_utils::api_serialization::{ get_entry::{GetEntryOptions, GetEntryResult, GetEntryResultItem, GetEntryResultType}, - get_links::{GetLinksArgs, GetLinksOptions, GetLinksResult, GetLinksResultCount,GetLinksBy}, + get_links::{GetLinksArgs, GetLinksOptions, GetLinksResult, GetLinksResultCount}, }; /// Consumes four values; the address of an entry get get links from (the base), the type of the links @@ -81,14 +81,12 @@ pub fn get_links_count_with_options( ) -> ZomeApiResult { let type_re = link_type.to_regex_string()?; let tag_re = tag.to_regex_string()?; - - let get_links_args = GetLinksBy::GetLinksArgs(GetLinksArgs { + Dispatch::GetLinksCount.with_input(GetLinksArgs { entry_address: base.clone(), link_type: type_re, tag: tag_re, options, - }); - Dispatch::GetLinksCount.with_input(get_links_args) + }) } pub fn get_links_count( @@ -99,16 +97,6 @@ pub fn get_links_count( get_links_count_with_options(base, link_type, tag, GetLinksOptions::default()) } -pub fn get_links_by_tag( - tag: LinkMatch<&str>, - options : GetLinksOptions -) -> ZomeApiResult { - let tag_re = tag.to_regex_string()?; - let get_links_args = GetLinksBy::Tag(tag_re,options); - Dispatch::GetLinksCount.with_input(get_links_args) -} - - /// Helper function for get_links. Returns a vector with the default return results. pub fn get_links( base: &Address, diff --git a/wasm_utils/src/api_serialization/get_links.rs b/wasm_utils/src/api_serialization/get_links.rs index 94cb90f170..cd71ea85eb 100644 --- a/wasm_utils/src/api_serialization/get_links.rs +++ b/wasm_utils/src/api_serialization/get_links.rs @@ -51,13 +51,6 @@ pub struct GetLinksResult { links: Vec, } -#[derive(Deserialize, Debug, Serialize, DefaultJson, Clone, PartialEq, Hash, Eq)] -pub enum GetLinksBy -{ - GetLinksArgs(GetLinksArgs), - Tag(String,GetLinksOptions) -} - #[derive(Deserialize, Serialize, Debug, DefaultJson)] pub struct GetLinksResultCount { pub count: usize, From d20bf0ca57dac3bb08ecc35c26cc516ca6052919 Mon Sep 17 00:00:00 2001 From: Purple Hair Rust Bard Date: Fri, 5 Jul 2019 21:02:11 -0400 Subject: [PATCH 34/48] Update CHANGELOG-UNRELEASED.md --- CHANGELOG-UNRELEASED.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/CHANGELOG-UNRELEASED.md b/CHANGELOG-UNRELEASED.md index d42391fba1..f4043de8cc 100644 --- a/CHANGELOG-UNRELEASED.md +++ b/CHANGELOG-UNRELEASED.md @@ -5,13 +5,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 {{ version-heading }} ### Added - -- Added `properties` to entry definitions (not to the entries themselved). These can be retrieved using the `entry_type_properties` HDK function [#1337](https://github.com/holochain/holochain-rust/pull/1337) -- *Breaking Change* Added type field to conductor network configuration. You must add `type="n3h"` for current config files to work. [#1540](https://github.com/holochain/holochain-rust/pull/1540) -- Added `Encryption` and `Decryption` methods in the HDK [#1534](https://github.com/holochain/holochain-rust/pull/1534) -- Adds `hc hash` CLI subcommand. Can be used to compute the hash of the DNA in the current dist directory or passed a path to a DNA with the --path flag [#1562](https://github.com/holochain/holochain-rust/pull/1562) -- Adds a --dna flag to the CLI so `hc run` can run DNAs outside the standard ./dist/ directory [1561](https://github.com/holochain/holochain-rust/pull/1561) -- Added a `get_links_count` method which allows the user to get number of links by base and tag [#1568](https://github.com/holochain/holochain-rust/pull/1568) +-- Added a `get_links_count` method which allows the user to get number of links by base and tag [#1568](https://github.com/holochain/holochain-rust/pull/1568) ### Changed From e889a957faaeac399d10fa52a2204cb19331d53c Mon Sep 17 00:00:00 2001 From: Purple Hair Rust Bard Date: Mon, 8 Jul 2019 12:10:30 -0400 Subject: [PATCH 35/48] Trigger CI again --- app_spec/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index 8ab7a40af8..2ee231345b 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -108,7 +108,7 @@ scenario('show_env', async (s, t, { alice }) => { t.equal(result.Ok.agent_id, '{"nick":"alice::app","pub_sign_key":"' + alice.app.agentId + '"}') t.equal(result.Ok.properties, '{"test_property":"test-property-value"}') - // don't compare the public token because it changes every time we change the dna + // don't compare the public token because it changes every time we change the dna. t.deepEqual(result.Ok.cap_request.provenance, [ alice.app.agentId, 'HFQkrDmnSOcmGQnYNtaYZWj89rlIQVFg0PpEoeFyx/Qw6Oizy5PI+tcsO8wYrllkuVPPzF5P3pvbCctKkfyGBg==' ] ); From eca611a8140d664a8a2116bd1d8f77a67a6be8d3 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Mon, 15 Jul 2019 11:52:12 -0400 Subject: [PATCH 36/48] Changed to use enums --- core/src/action.rs | 11 ++-- core/src/network/actions/get_links.rs | 10 +-- core/src/network/handler/query.rs | 66 ++++++++----------- core/src/network/query.rs | 20 ++++-- core/src/network/reducers/get_links.rs | 9 +-- core/src/network/reducers/get_links_count.rs | 47 ------------- .../reducers/handle_get_links_result.rs | 3 +- .../reducers/handle_get_links_result_count.rs | 13 ---- core/src/network/reducers/mod.rs | 9 --- .../src/network/reducers/respond_get_links.rs | 7 +- .../reducers/respond_get_links_count.rs | 62 ----------------- core/src/network/state.rs | 6 +- core/src/nucleus/ribosome/api/remove_link.rs | 7 +- core/src/workflows/get_link_result.rs | 9 ++- 14 files changed, 80 insertions(+), 199 deletions(-) delete mode 100644 core/src/network/reducers/get_links_count.rs delete mode 100644 core/src/network/reducers/handle_get_links_result_count.rs delete mode 100644 core/src/network/reducers/respond_get_links_count.rs diff --git a/core/src/action.rs b/core/src/action.rs index 0fe60b3eb6..0cb12fcc9b 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -3,6 +3,7 @@ use crate::{ network::{ direct_message::DirectMessage, entry_aspect::EntryAspect, entry_with_header::EntryWithHeader, state::NetworkState, + query::{GetLinksNetworkQuery,GetLinksNetworkResult} }, nucleus::{ actions::{call_zome_function::ExecuteZomeFnResponse, initialize::Initialization}, @@ -158,14 +159,12 @@ pub enum Action { /// get links from entry address and link_type name /// Last string is the stringified process unique id of this `hdk::get_links` call. - GetLinks(GetLinksKey), + GetLinks((GetLinksKey,GetLinksNetworkQuery)), GetLinksTimeout(GetLinksKey), GetLinksCount((GetLinksKey, Option)), - RespondGetLinks((QueryEntryData, Vec<(Address, CrudStatus)>, String, String)), - RespondGetLinksCount((QueryEntryData, usize, String, String)), - HandleGetLinksResult((Vec<(Address, CrudStatus)>, GetLinksKey)), - HandleGetLinksResultCount((usize, GetLinksKey)), - + RespondGetLinks((QueryEntryData, GetLinksNetworkResult, String, String)), + HandleGetLinksResult((GetLinksNetworkResult, GetLinksKey)), + /// Makes the network module send a direct (node-to-node) message /// to the address given in [DirectMessageData](struct.DirectMessageData.html) SendDirectMessage(DirectMessageData), diff --git a/core/src/network/actions/get_links.rs b/core/src/network/actions/get_links.rs index 6df8f73345..5234ac4a05 100644 --- a/core/src/network/actions/get_links.rs +++ b/core/src/network/actions/get_links.rs @@ -2,16 +2,18 @@ use crate::{ action::{Action, ActionWrapper, GetLinksKey}, context::Context, instance::dispatch_action, + network::query::{GetLinksNetworkQuery,GetLinksNetworkResult} }; use futures::{ future::Future, task::{LocalWaker, Poll}, }; -use holochain_core_types::{crud_status::CrudStatus, error::HcResult, time::Timeout}; +use holochain_core_types::{ error::HcResult, time::Timeout}; use holochain_persistence_api::cas::content::Address; use snowflake::ProcessUniqueId; use std::{pin::Pin, sync::Arc, thread}; + /// GetLinks Action Creator /// This is the network version of get_links that makes the network module start /// a look-up process. @@ -21,14 +23,14 @@ pub async fn get_links( link_type: String, tag: String, timeout: Timeout, -) -> HcResult> { +) -> HcResult { let key = GetLinksKey { base_address: address.clone(), link_type: link_type.clone(), tag: tag.clone(), id: ProcessUniqueId::new().to_string(), }; - let action_wrapper = ActionWrapper::new(Action::GetLinks(key.clone())); + let action_wrapper = ActionWrapper::new(Action::GetLinks((key.clone(),GetLinksNetworkQuery::Links))); dispatch_action(context.action_channel(), action_wrapper.clone()); let key_inner = key.clone(); @@ -56,7 +58,7 @@ pub struct GetLinksFuture { } impl Future for GetLinksFuture { - type Output = HcResult>; + type Output = HcResult; fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { if let Some(err) = self.context.action_channel_error("GetLinksFuture") { diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index a6f3e7a412..38f45a6ff9 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -3,7 +3,7 @@ use crate::{ context::Context, entry::CanPublish, instance::dispatch_action, - network::query::{NetworkQuery, NetworkQueryResult}, + network::query::{NetworkQuery, NetworkQueryResult,GetLinksNetworkQuery,GetLinksNetworkResult}, nucleus, }; use holochain_core_types::{crud_status::CrudStatus, entry::EntryWithMetaAndHeader}; @@ -70,7 +70,7 @@ fn get_entry(context: &Arc, address: Address) -> Option) { let query_json = JsonString::from_json(&String::from_utf8(query_data.query.clone()).unwrap()); let action_wrapper = match query_json.clone().try_into() { - Ok(NetworkQuery::GetLinks(link_type, tag)) => { + Ok(NetworkQuery::GetLinks(link_type, tag,_options,query)) => { let links = get_links( &context, query_data.entry_address.clone(), @@ -78,28 +78,25 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc tag.clone(), None, ); + let links_result = match query + { + GetLinksNetworkQuery::Links => + { + GetLinksNetworkResult::Links(links) + }, + GetLinksNetworkQuery::Count => + { + GetLinksNetworkResult::Count(links.len()) + } + }; + ActionWrapper::new(Action::RespondGetLinks(( - query_data, - links, - link_type.clone(), - tag.clone(), - ))) - } - Ok(NetworkQuery::GetLinksCount(link_type, tag, crud)) => { - let links_count = get_links( - &context, - query_data.entry_address.clone(), - link_type.clone(), - tag.clone(), - crud.clone(), - ) - .len(); - ActionWrapper::new(Action::RespondGetLinksCount(( - query_data, - links_count, - link_type.clone(), - tag.clone(), - ))) + query_data, + links_result, + link_type.clone(), + tag.clone(), + ))) + } Ok(NetworkQuery::GetEntry) => { let maybe_entry = get_entry(&context, query_data.entry_address.clone()); @@ -131,27 +128,18 @@ pub fn handle_query_entry_result(query_result_data: QueryEntryResultData, contex }, ))) } - Ok(NetworkQueryResult::Links(links, link_type, tag)) => { + Ok(NetworkQueryResult::Links(links_result, link_type, tag)) => { + ActionWrapper::new(Action::HandleGetLinksResult(( - links, - GetLinksKey { + links_result, + GetLinksKey { base_address: query_result_data.entry_address.clone(), link_type: link_type.clone(), tag: tag.clone(), id: query_result_data.request_id.clone(), - }, - ))) - } - Ok(NetworkQueryResult::LinksCount(links_count, link_type, tag)) => { - ActionWrapper::new(Action::HandleGetLinksResultCount(( - links_count, - GetLinksKey { - base_address: query_result_data.entry_address.clone(), - link_type: link_type.clone(), - tag: tag.clone(), - id: query_result_data.request_id.clone(), - }, - ))) + }, + ))) + } err => { context.log(format!( diff --git a/core/src/network/query.rs b/core/src/network/query.rs index cc4545c4b8..4848a53394 100644 --- a/core/src/network/query.rs +++ b/core/src/network/query.rs @@ -2,16 +2,28 @@ use holochain_core_types::{crud_status::CrudStatus, entry::EntryWithMetaAndHeade use holochain_json_api::{error::JsonError, json::JsonString}; use holochain_persistence_api::cas::content::Address; +#[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] +pub enum GetLinksNetworkQuery +{ + Count, + Links +} + +#[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] +pub enum GetLinksNetworkResult +{ + Count(usize), + Links(Vec<(Address, CrudStatus)>) +} + #[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] pub enum NetworkQuery { GetEntry, - GetLinks(String, String), - GetLinksCount(String, String, Option), + GetLinks(String, String,Option,GetLinksNetworkQuery), } #[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] pub enum NetworkQueryResult { Entry(Option), - Links(Vec<(Address, CrudStatus)>, String, String), - LinksCount(usize, String, String), + Links(GetLinksNetworkResult,String,String) } diff --git a/core/src/network/reducers/get_links.rs b/core/src/network/reducers/get_links.rs index adb8757ae8..4b7e495e80 100644 --- a/core/src/network/reducers/get_links.rs +++ b/core/src/network/reducers/get_links.rs @@ -1,6 +1,6 @@ use crate::{ action::{ActionWrapper, GetLinksKey}, - network::{query::NetworkQuery, reducers::send, state::NetworkState}, + network::{query::{NetworkQuery,GetLinksNetworkQuery}, reducers::send, state::NetworkState}, state::State, }; @@ -12,10 +12,11 @@ use holochain_persistence_api::hash::HashString; fn reduce_get_links_inner( network_state: &mut NetworkState, key: &GetLinksKey, + get_links_query : &GetLinksNetworkQuery ) -> Result<(), HolochainError> { network_state.initialized()?; let query_json: JsonString = - NetworkQuery::GetLinks(key.link_type.clone(), key.tag.clone()).into(); + NetworkQuery::GetLinks(key.link_type.clone(), key.tag.clone(),None,get_links_query.clone()).into(); send( network_state, JsonProtocol::QueryEntry(QueryEntryData { @@ -34,9 +35,9 @@ pub fn reduce_get_links( action_wrapper: &ActionWrapper, ) { let action = action_wrapper.action(); - let key = unwrap_to!(action => crate::action::Action::GetLinks); + let (key,query) = unwrap_to!(action => crate::action::Action::GetLinks); - let result = match reduce_get_links_inner(network_state, &key) { + let result = match reduce_get_links_inner(network_state, &key,&query) { Ok(()) => None, Err(err) => Some(Err(err)), }; diff --git a/core/src/network/reducers/get_links_count.rs b/core/src/network/reducers/get_links_count.rs deleted file mode 100644 index efff98f9a6..0000000000 --- a/core/src/network/reducers/get_links_count.rs +++ /dev/null @@ -1,47 +0,0 @@ -use crate::{ - action::{ActionWrapper, GetLinksKey}, - network::{query::NetworkQuery, reducers::send, state::NetworkState}, - state::State, -}; - -use holochain_core_types::{crud_status::CrudStatus, error::HolochainError}; -use holochain_json_api::json::JsonString; -use holochain_net::connection::json_protocol::{JsonProtocol, QueryEntryData}; -use holochain_persistence_api::hash::HashString; - -fn reduce_get_links_inner( - network_state: &mut NetworkState, - key: &GetLinksKey, - crud_status: Option, -) -> Result<(), HolochainError> { - network_state.initialized()?; - let query_json: JsonString = - NetworkQuery::GetLinksCount(key.link_type.clone(), key.tag.clone(), crud_status).into(); - send( - network_state, - JsonProtocol::QueryEntry(QueryEntryData { - requester_agent_id: network_state.agent_id.clone().unwrap().into(), - request_id: key.id.clone(), - dna_address: network_state.dna_address.clone().unwrap(), - entry_address: HashString::from(key.base_address.clone()), - query: query_json.to_string().into_bytes(), - }), - ) -} -pub fn reduce_get_links_count( - network_state: &mut NetworkState, - _root_state: &State, - action_wrapper: &ActionWrapper, -) { - let action = action_wrapper.action(); - let (key, crud) = unwrap_to!(action => crate::action::Action::GetLinksCount); - - let result = match reduce_get_links_inner(network_state, &key, crud.clone()) { - Ok(()) => None, - Err(err) => Some(Err(err)), - }; - - network_state - .get_links_results_count - .insert(key.clone(), result); -} diff --git a/core/src/network/reducers/handle_get_links_result.rs b/core/src/network/reducers/handle_get_links_result.rs index 78fb39854d..7647775528 100644 --- a/core/src/network/reducers/handle_get_links_result.rs +++ b/core/src/network/reducers/handle_get_links_result.rs @@ -1,4 +1,4 @@ -use crate::{action::ActionWrapper, network::state::NetworkState, state::State}; +use crate::{action::ActionWrapper, network::state::NetworkState,state::State}; pub fn reduce_handle_get_links_result( network_state: &mut NetworkState, @@ -7,6 +7,7 @@ pub fn reduce_handle_get_links_result( ) { let action = action_wrapper.action(); let (links, key) = unwrap_to!(action => crate::action::Action::HandleGetLinksResult); + network_state .get_links_results .insert(key.clone(), Some(Ok(links.clone()))); diff --git a/core/src/network/reducers/handle_get_links_result_count.rs b/core/src/network/reducers/handle_get_links_result_count.rs deleted file mode 100644 index bd17ad343b..0000000000 --- a/core/src/network/reducers/handle_get_links_result_count.rs +++ /dev/null @@ -1,13 +0,0 @@ -use crate::{action::ActionWrapper, network::state::NetworkState, state::State}; - -pub fn reduce_handle_get_links_count( - network_state: &mut NetworkState, - _root_state: &State, - action_wrapper: &ActionWrapper, -) { - let action = action_wrapper.action(); - let (links_count, key) = unwrap_to!(action => crate::action::Action::HandleGetLinksResultCount); - network_state - .get_links_results_count - .insert(key.clone(), Some(Ok(links_count.clone()))); -} diff --git a/core/src/network/reducers/mod.rs b/core/src/network/reducers/mod.rs index ecc55b94a8..3ab63c6b00 100644 --- a/core/src/network/reducers/mod.rs +++ b/core/src/network/reducers/mod.rs @@ -1,10 +1,8 @@ pub mod get_entry; pub mod get_links; -pub mod get_links_count; pub mod get_validation_package; pub mod handle_custom_send_response; pub mod handle_get_links_result; -pub mod handle_get_links_result_count; pub mod handle_get_result; pub mod handle_get_validation_package; pub mod init; @@ -14,7 +12,6 @@ pub mod respond_authoring_list; pub mod respond_fetch; pub mod respond_get; pub mod respond_get_links; -pub mod respond_get_links_count; pub mod respond_gossip_list; pub mod send_direct_message; pub mod shutdown; @@ -26,11 +23,9 @@ use crate::{ reducers::{ get_entry::{reduce_get_entry, reduce_get_entry_timeout}, get_links::{reduce_get_links, reduce_get_links_timeout}, - get_links_count::reduce_get_links_count, get_validation_package::reduce_get_validation_package, handle_custom_send_response::reduce_handle_custom_send_response, handle_get_links_result::reduce_handle_get_links_result, - handle_get_links_result_count::reduce_handle_get_links_count, handle_get_result::reduce_handle_get_result, handle_get_validation_package::reduce_handle_get_validation_package, init::reduce_init, @@ -40,7 +35,6 @@ use crate::{ respond_fetch::reduce_respond_fetch_data, respond_get::reduce_respond_get, respond_get_links::reduce_respond_get_links, - respond_get_links_count::reduce_respond_get_links_count, respond_gossip_list::reduce_respond_gossip_list, send_direct_message::{reduce_send_direct_message, reduce_send_direct_message_timeout}, shutdown::reduce_shutdown, @@ -65,14 +59,12 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::GetEntry(_) => Some(reduce_get_entry), Action::GetEntryTimeout(_) => Some(reduce_get_entry_timeout), Action::GetLinks(_) => Some(reduce_get_links), - Action::GetLinksCount(_) => Some(reduce_get_links_count), Action::GetLinksTimeout(_) => Some(reduce_get_links_timeout), Action::GetValidationPackage(_) => Some(reduce_get_validation_package), Action::HandleCustomSendResponse(_) => Some(reduce_handle_custom_send_response), Action::HandleGetResult(_) => Some(reduce_handle_get_result), Action::HandleGetLinksResult(_) => Some(reduce_handle_get_links_result), Action::HandleGetValidationPackage(_) => Some(reduce_handle_get_validation_package), - Action::HandleGetLinksResultCount(_) => Some(reduce_handle_get_links_count), Action::InitNetwork(_) => Some(reduce_init), Action::Publish(_) => Some(reduce_publish), Action::ResolveDirectConnection(_) => Some(reduce_resolve_direct_connection), @@ -81,7 +73,6 @@ fn resolve_reducer(action_wrapper: &ActionWrapper) -> Option { Action::RespondFetch(_) => Some(reduce_respond_fetch_data), Action::RespondGet(_) => Some(reduce_respond_get), Action::RespondGetLinks(_) => Some(reduce_respond_get_links), - Action::RespondGetLinksCount(_) => Some(reduce_respond_get_links_count), Action::SendDirectMessage(_) => Some(reduce_send_direct_message), Action::SendDirectMessageTimeout(_) => Some(reduce_send_direct_message_timeout), Action::ShutdownNetwork => Some(reduce_shutdown), diff --git a/core/src/network/reducers/respond_get_links.rs b/core/src/network/reducers/respond_get_links.rs index 1fb24c7385..d8d00e1e21 100644 --- a/core/src/network/reducers/respond_get_links.rs +++ b/core/src/network/reducers/respond_get_links.rs @@ -1,23 +1,22 @@ use crate::{ action::ActionWrapper, network::{ - actions::ActionResponse, query::NetworkQueryResult, reducers::send, state::NetworkState, + actions::ActionResponse, query::{NetworkQueryResult,GetLinksNetworkResult}, reducers::send, state::NetworkState, }, state::State, }; -use holochain_core_types::{crud_status::CrudStatus, error::HolochainError}; +use holochain_core_types::{ error::HolochainError}; use holochain_json_api::json::JsonString; use holochain_net::connection::json_protocol::{ JsonProtocol, QueryEntryData, QueryEntryResultData, }; -use holochain_persistence_api::cas::content::Address; /// Send back to network a HandleQueryEntryResult, no matter what. /// Will return an empty content field if it actually doesn't have the data. fn reduce_respond_get_links_inner( network_state: &mut NetworkState, query_data: &QueryEntryData, - links: &Vec<(Address, CrudStatus)>, + links: &GetLinksNetworkResult, link_type: String, tag: String, ) -> Result<(), HolochainError> { diff --git a/core/src/network/reducers/respond_get_links_count.rs b/core/src/network/reducers/respond_get_links_count.rs deleted file mode 100644 index df0664ac1f..0000000000 --- a/core/src/network/reducers/respond_get_links_count.rs +++ /dev/null @@ -1,62 +0,0 @@ -use crate::{ - action::ActionWrapper, - network::{ - actions::ActionResponse, query::NetworkQueryResult, reducers::send, state::NetworkState, - }, - state::State, -}; -use holochain_core_types::error::HolochainError; -use holochain_json_api::json::JsonString; -use holochain_net::connection::json_protocol::{ - JsonProtocol, QueryEntryData, QueryEntryResultData, -}; - -/// Send back to network a HandleQueryEntryResult, no matter what. -/// Will return an empty content field if it actually doesn't have the data. -fn reduce_respond_get_links_count_inner( - network_state: &mut NetworkState, - query_data: &QueryEntryData, - links_count: usize, - link_type: String, - tag: String, -) -> Result<(), HolochainError> { - network_state.initialized()?; - let query_result_json: JsonString = - NetworkQueryResult::LinksCount(links_count.clone(), link_type, tag).into(); - send( - network_state, - JsonProtocol::HandleQueryEntryResult(QueryEntryResultData { - request_id: query_data.request_id.clone(), - requester_agent_id: query_data.requester_agent_id.clone(), - dna_address: network_state.dna_address.clone().unwrap(), - responder_agent_id: network_state.agent_id.clone().unwrap().into(), - entry_address: query_data.entry_address.clone().into(), - query_result: query_result_json.to_string().into_bytes(), - }), - ) -} - -pub fn reduce_respond_get_links_count( - network_state: &mut NetworkState, - _root_state: &State, - action_wrapper: &ActionWrapper, -) { - let action = action_wrapper.action(); - let (query_data, links_count, link_type, tag) = - unwrap_to!(action => crate::action::Action::RespondGetLinksCount); - let result = reduce_respond_get_links_count_inner( - network_state, - query_data, - links_count.clone(), - link_type.clone(), - tag.clone(), - ); - - network_state.actions.insert( - action_wrapper.clone(), - ActionResponse::RespondGetLinksCount(match result { - Ok(_) => Ok(()), - Err(e) => Err(HolochainError::ErrorGeneric(e.to_string())), - }), - ); -} diff --git a/core/src/network/state.rs b/core/src/network/state.rs index 4ab81b1df1..acee63abe9 100644 --- a/core/src/network/state.rs +++ b/core/src/network/state.rs @@ -1,10 +1,10 @@ use crate::{ action::{ActionWrapper, GetEntryKey, GetLinksKey}, - network::{actions::ActionResponse, direct_message::DirectMessage}, + network::{actions::ActionResponse, direct_message::DirectMessage,query::GetLinksNetworkResult}, }; use boolinator::*; use holochain_core_types::{ - crud_status::CrudStatus, entry::EntryWithMetaAndHeader, error::HolochainError, + entry::EntryWithMetaAndHeader, error::HolochainError, validation::ValidationPackage, }; use holochain_net::p2p_network::P2pNetwork; @@ -28,7 +28,7 @@ type GetEntryWithMetaResult = Option, Holo /// None: process started, but no response yet from the network /// Some(Err(_)): there was a problem at some point /// Some(Ok(_)): we got the list of links -type GetLinksResult = Option, HolochainError>>; +type GetLinksResult = Option>; type GetLinksResultCount = Option>; diff --git a/core/src/nucleus/ribosome/api/remove_link.rs b/core/src/nucleus/ribosome/api/remove_link.rs index 290b5a0ef2..878e12a100 100644 --- a/core/src/nucleus/ribosome/api/remove_link.rs +++ b/core/src/nucleus/ribosome/api/remove_link.rs @@ -1,5 +1,5 @@ use crate::{ - network::actions::get_links::get_links, + network::{actions::get_links::get_links,query::GetLinksNetworkResult}, nucleus::ribosome::{api::ZomeApiResult, Runtime}, workflows::{author_entry::author_entry, get_entry_result::get_entry_result_workflow}, }; @@ -70,6 +70,11 @@ pub fn invoke_remove_link(runtime: &mut Runtime, args: &RuntimeArgs) -> ZomeApiR ribosome_error_code!(WorkflowFailed) } else { let links = links_result.expect("This is supposed to not fail"); + let links = match links + { + GetLinksNetworkResult::Links(links) => links, + _ => return ribosome_error_code!(WorkflowFailed) + }; let filtered_links = links .into_iter() .filter(|link_crud| link_crud.1 == CrudStatus::Live) diff --git a/core/src/workflows/get_link_result.rs b/core/src/workflows/get_link_result.rs index 792eef6cec..1554f79f35 100644 --- a/core/src/workflows/get_link_result.rs +++ b/core/src/workflows/get_link_result.rs @@ -1,5 +1,5 @@ use crate::{ - context::Context, network::actions::get_links::get_links, + context::Context, network::{actions::get_links::get_links,query::GetLinksNetworkResult}, workflows::get_entry_result::get_entry_result_workflow, }; @@ -42,7 +42,7 @@ pub async fn get_link_add_entries<'a>( link_args: &'a GetLinksArgs, ) -> Result, CrudStatus)>, HolochainError> { //get link add entries - let links_caches = await!(get_links( + let links_result = await!(get_links( context.clone(), link_args.entry_address.clone(), link_args.link_type.clone(), @@ -51,6 +51,11 @@ pub async fn get_link_add_entries<'a>( ))?; //iterate over link add entries + let links_caches = match links_result + { + GetLinksNetworkResult::Links(links_caches) => Ok(links_caches), + _ => Err(HolochainError::ErrorGeneric("Should only get link caches".to_string())) + }?; let (links_result, get_links_error): (Vec<_>, Vec<_>) = links_caches .iter() .map(|s| { From 1a46d8687d71fd14d3a942a8b2cf76445f26f871 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Mon, 15 Jul 2019 13:22:09 -0400 Subject: [PATCH 37/48] links refactor --- core/src/action.rs | 3 +- core/src/network/actions/get_links.rs | 26 ++++--- core/src/network/actions/get_links_count.rs | 81 -------------------- core/src/network/actions/mod.rs | 2 - core/src/network/handler/query.rs | 4 +- core/src/network/mod.rs | 16 +++- core/src/network/reducers/get_links.rs | 14 ++-- core/src/nucleus/ribosome/api/remove_link.rs | 18 +++-- core/src/workflows/get_link_result.rs | 15 +--- core/src/workflows/get_links_count.rs | 17 ++-- 10 files changed, 65 insertions(+), 131 deletions(-) delete mode 100644 core/src/network/actions/get_links_count.rs diff --git a/core/src/action.rs b/core/src/action.rs index 0cb12fcc9b..daf951bddd 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -159,9 +159,8 @@ pub enum Action { /// get links from entry address and link_type name /// Last string is the stringified process unique id of this `hdk::get_links` call. - GetLinks((GetLinksKey,GetLinksNetworkQuery)), + GetLinks((GetLinksKey,Option,GetLinksNetworkQuery)), GetLinksTimeout(GetLinksKey), - GetLinksCount((GetLinksKey, Option)), RespondGetLinks((QueryEntryData, GetLinksNetworkResult, String, String)), HandleGetLinksResult((GetLinksNetworkResult, GetLinksKey)), diff --git a/core/src/network/actions/get_links.rs b/core/src/network/actions/get_links.rs index 5234ac4a05..aed86fbfbc 100644 --- a/core/src/network/actions/get_links.rs +++ b/core/src/network/actions/get_links.rs @@ -8,33 +8,39 @@ use futures::{ future::Future, task::{LocalWaker, Poll}, }; -use holochain_core_types::{ error::HcResult, time::Timeout}; -use holochain_persistence_api::cas::content::Address; +use holochain_core_types::{error::HcResult,crud_status::CrudStatus}; use snowflake::ProcessUniqueId; use std::{pin::Pin, sync::Arc, thread}; +use holochain_wasm_utils::api_serialization::get_links::{GetLinksArgs,LinksStatusRequestKind}; + /// GetLinks Action Creator /// This is the network version of get_links that makes the network module start /// a look-up process. pub async fn get_links( context: Arc, - address: Address, - link_type: String, - tag: String, - timeout: Timeout, + link_args: &GetLinksArgs, + query : GetLinksNetworkQuery ) -> HcResult { let key = GetLinksKey { - base_address: address.clone(), - link_type: link_type.clone(), - tag: tag.clone(), + base_address: link_args.entry_address.clone(), + link_type: link_args.link_type.clone(), + tag: link_args.tag.clone(), id: ProcessUniqueId::new().to_string(), }; - let action_wrapper = ActionWrapper::new(Action::GetLinks((key.clone(),GetLinksNetworkQuery::Links))); + let crud_status = match link_args.options.status_request + { + LinksStatusRequestKind::All => None, + LinksStatusRequestKind::Deleted => Some(CrudStatus::Deleted), + LinksStatusRequestKind::Live => Some(CrudStatus::Live) + }; + let action_wrapper = ActionWrapper::new(Action::GetLinks((key.clone(),crud_status,query))); dispatch_action(context.action_channel(), action_wrapper.clone()); let key_inner = key.clone(); let context_inner = context.clone(); + let timeout = link_args.options.timeout.clone(); thread::Builder::new() .name(format!("get_links/{:?}", key)) .spawn(move || { diff --git a/core/src/network/actions/get_links_count.rs b/core/src/network/actions/get_links_count.rs deleted file mode 100644 index 45f3ab76b8..0000000000 --- a/core/src/network/actions/get_links_count.rs +++ /dev/null @@ -1,81 +0,0 @@ -use crate::{ - action::{Action, ActionWrapper, GetLinksKey}, - context::Context, - instance::dispatch_action, -}; -use futures::{ - future::Future, - task::{LocalWaker, Poll}, -}; -use holochain_core_types::{crud_status::CrudStatus, error::HcResult, time::Timeout}; -use holochain_persistence_api::cas::content::Address; -use holochain_wasm_utils::api_serialization::get_links::LinksStatusRequestKind; -use snowflake::ProcessUniqueId; -use std::{pin::Pin, sync::Arc, thread}; - -/// GetLinks Action Creator -/// This is the network version of get_links that makes the network module start -/// a look-up process. -pub async fn get_links_count( - context: Arc, - address: Address, - link_type: String, - tag: String, - timeout: Timeout, - link_status_request: LinksStatusRequestKind, -) -> HcResult { - let key = GetLinksKey { - base_address: address.clone(), - link_type: link_type.clone(), - tag: tag.clone(), - id: ProcessUniqueId::new().to_string(), - }; - - let crud_status = match link_status_request { - LinksStatusRequestKind::All => None, - LinksStatusRequestKind::Live => Some(CrudStatus::Live), - LinksStatusRequestKind::Deleted => Some(CrudStatus::Deleted), - }; - let action_wrapper = ActionWrapper::new(Action::GetLinksCount((key.clone(), crud_status))); - dispatch_action(context.action_channel(), action_wrapper.clone()); - - let key_inner = key.clone(); - let context_inner = context.clone(); - let _ = thread::spawn(move || { - thread::sleep(timeout.into()); - let action_wrapper = ActionWrapper::new(Action::GetLinksTimeout(key_inner)); - dispatch_action(context_inner.action_channel(), action_wrapper.clone()); - }); - - await!(GetLinksCountFuture { - context: context.clone(), - key - }) -} - -/// GetLinksFuture resolves to a HcResult>. -/// Tracks the state of the network module -pub struct GetLinksCountFuture { - context: Arc, - key: GetLinksKey, -} - -impl Future for GetLinksCountFuture { - type Output = HcResult; - - fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - let state = self.context.state().unwrap().network(); - if let Err(error) = state.initialized() { - return Poll::Ready(Err(error)); - } - // - // TODO: connect the waker to state updates for performance reasons - // See: https://github.com/holochain/holochain-rust/issues/314 - // - lw.wake(); - match state.get_links_results_count.get(&self.key) { - Some(Some(result)) => Poll::Ready(result.clone()), - _ => Poll::Pending, - } - } -} diff --git a/core/src/network/actions/mod.rs b/core/src/network/actions/mod.rs index 049bbdcbb2..918c99c63a 100644 --- a/core/src/network/actions/mod.rs +++ b/core/src/network/actions/mod.rs @@ -1,7 +1,6 @@ pub mod custom_send; pub mod get_entry; pub mod get_links; -pub mod get_links_count; pub mod get_validation_package; pub mod initialize_network; pub mod publish; @@ -16,5 +15,4 @@ pub enum ActionResponse { RespondGet(HcResult<()>), RespondFetch(HcResult<()>), RespondGetLinks(HcResult<()>), - RespondGetLinksCount(HcResult<()>), } diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index 38f45a6ff9..0da2026193 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -70,13 +70,13 @@ fn get_entry(context: &Arc, address: Address) -> Option) { let query_json = JsonString::from_json(&String::from_utf8(query_data.query.clone()).unwrap()); let action_wrapper = match query_json.clone().try_into() { - Ok(NetworkQuery::GetLinks(link_type, tag,_options,query)) => { + Ok(NetworkQuery::GetLinks(link_type, tag,options,query)) => { let links = get_links( &context, query_data.entry_address.clone(), link_type.clone(), tag.clone(), - None, + options, ); let links_result = match query { diff --git a/core/src/network/mod.rs b/core/src/network/mod.rs index d6883fd040..5a07b39963 100644 --- a/core/src/network/mod.rs +++ b/core/src/network/mod.rs @@ -20,6 +20,7 @@ pub mod tests { get_validation_package::get_validation_package, publish::publish, }, test_utils::test_wat_always_valid, + query::{GetLinksNetworkQuery,GetLinksNetworkResult} }, workflows::author_entry::author_entry, }; @@ -33,6 +34,7 @@ pub mod tests { use holochain_json_api::json::JsonString; use holochain_persistence_api::cas::content::{Address, AddressableContent}; use test_utils::*; + use holochain_wasm_utils::api_serialization::get_links::GetLinksArgs; // TODO: Should wait for a success or saturation response from the network module after Publish #[test] @@ -289,16 +291,22 @@ pub mod tests { // std::thread::sleep(std::time::Duration::from_millis(1000)); println!("\n get_links() ..."); + let get_links_args = GetLinksArgs + { + entry_address : entry_addresses[0].clone(), + link_type : "test-link".into(), + tag : "test-tag".into(), + options : Default::default() + }; let maybe_links = context2.block_on(get_links( context2.clone(), - entry_addresses[0].clone(), - "test-link".into(), - "test-tag".into(), - Default::default(), + &get_links_args, + GetLinksNetworkQuery::Links )); assert!(maybe_links.is_ok()); let links = maybe_links.unwrap(); + let links = unwrap_to!(links=>GetLinksNetworkResult::Links); assert_eq!(links.len(), 2, "links = {:?}", links); // can be in any order assert!( diff --git a/core/src/network/reducers/get_links.rs b/core/src/network/reducers/get_links.rs index 4b7e495e80..c65f8a9e99 100644 --- a/core/src/network/reducers/get_links.rs +++ b/core/src/network/reducers/get_links.rs @@ -4,7 +4,7 @@ use crate::{ state::State, }; -use holochain_core_types::error::HolochainError; +use holochain_core_types::{error::HolochainError,crud_status::CrudStatus}; use holochain_json_api::json::JsonString; use holochain_net::connection::json_protocol::{JsonProtocol, QueryEntryData}; use holochain_persistence_api::hash::HashString; @@ -12,11 +12,12 @@ use holochain_persistence_api::hash::HashString; fn reduce_get_links_inner( network_state: &mut NetworkState, key: &GetLinksKey, - get_links_query : &GetLinksNetworkQuery + get_links_query : &GetLinksNetworkQuery, + crud_status : &Option ) -> Result<(), HolochainError> { network_state.initialized()?; let query_json: JsonString = - NetworkQuery::GetLinks(key.link_type.clone(), key.tag.clone(),None,get_links_query.clone()).into(); + NetworkQuery::GetLinks(key.link_type.clone(), key.tag.clone(),crud_status.clone(),get_links_query.clone()).into(); send( network_state, JsonProtocol::QueryEntry(QueryEntryData { @@ -35,9 +36,9 @@ pub fn reduce_get_links( action_wrapper: &ActionWrapper, ) { let action = action_wrapper.action(); - let (key,query) = unwrap_to!(action => crate::action::Action::GetLinks); + let (key,crud_status,query) = unwrap_to!(action => crate::action::Action::GetLinks); - let result = match reduce_get_links_inner(network_state, &key,&query) { + let result = match reduce_get_links_inner(network_state, &key,&query,crud_status) { Ok(()) => None, Err(err) => Some(Err(err)), }; @@ -71,6 +72,7 @@ mod tests { action::{Action, ActionWrapper, GetLinksKey}, instance::tests::test_context, state::test_store, + network::query::GetLinksNetworkQuery }; use holochain_core_types::error::HolochainError; //use std::sync::{Arc, RwLock}; @@ -88,7 +90,7 @@ mod tests { tag: "link-tag".to_string(), id: snowflake::ProcessUniqueId::new().to_string(), }; - let action_wrapper = ActionWrapper::new(Action::GetLinks(key.clone())); + let action_wrapper = ActionWrapper::new(Action::GetLinks((key.clone(),None,GetLinksNetworkQuery::Links))); let store = store.reduce(action_wrapper); let maybe_get_links_result = store diff --git a/core/src/nucleus/ribosome/api/remove_link.rs b/core/src/nucleus/ribosome/api/remove_link.rs index 878e12a100..e09c47154b 100644 --- a/core/src/nucleus/ribosome/api/remove_link.rs +++ b/core/src/nucleus/ribosome/api/remove_link.rs @@ -1,5 +1,5 @@ use crate::{ - network::{actions::get_links::get_links,query::GetLinksNetworkResult}, + network::{actions::get_links::get_links,query::{GetLinksNetworkResult,GetLinksNetworkQuery}}, nucleus::ribosome::{api::ZomeApiResult, Runtime}, workflows::{author_entry::author_entry, get_entry_result::get_entry_result_workflow}, }; @@ -12,7 +12,7 @@ use holochain_core_types::{ }; use holochain_wasm_utils::api_serialization::{ get_entry::{GetEntryArgs, GetEntryOptions, GetEntryResultType}, - get_links::GetLinksOptions, + get_links::{GetLinksOptions,GetLinksArgs}, link_entries::LinkEntriesArgs, }; use std::convert::TryFrom; @@ -58,12 +58,18 @@ pub fn invoke_remove_link(runtime: &mut Runtime, args: &RuntimeArgs) -> ZomeApiR top_chain_header, context.agent_id.clone(), ); + let get_links_args = GetLinksArgs + { + entry_address : link.base().clone(), + link_type : link.link_type().clone(), + tag : link.tag().clone(), + options: GetLinksOptions::default() + + }; let links_result = context.block_on(get_links( context.clone(), - link.base().clone(), - link.link_type().clone(), - link.tag().clone(), - GetLinksOptions::default().timeout.clone(), + &get_links_args, + GetLinksNetworkQuery::Links )); if links_result.is_err() { context.log("err/zome : Could not get links for remove_link method"); diff --git a/core/src/workflows/get_link_result.rs b/core/src/workflows/get_link_result.rs index 1554f79f35..b5b12ceaa1 100644 --- a/core/src/workflows/get_link_result.rs +++ b/core/src/workflows/get_link_result.rs @@ -1,5 +1,5 @@ use crate::{ - context::Context, network::{actions::get_links::get_links,query::GetLinksNetworkResult}, + context::Context, network::{actions::get_links::get_links,query::{GetLinksNetworkQuery,GetLinksNetworkResult}}, workflows::get_entry_result::get_entry_result_workflow, }; @@ -9,7 +9,7 @@ use holochain_core_types::{ }; use holochain_wasm_utils::api_serialization::{ get_entry::{GetEntryArgs, GetEntryOptions, GetEntryResultType::Single}, - get_links::{GetLinksArgs, GetLinksResult, LinksResult, LinksStatusRequestKind}, + get_links::{GetLinksArgs, GetLinksResult, LinksResult}, }; use std::sync::Arc; @@ -21,11 +21,6 @@ pub async fn get_link_result_workflow<'a>( //get links based on status request, all for everything, deleted for deleted links and live for active links let link_results = links .into_iter() - .filter(|link_entry_crud| match link_args.options.status_request { - LinksStatusRequestKind::All => true, - LinksStatusRequestKind::Live => link_entry_crud.2 == CrudStatus::Live, - _ => link_entry_crud.2 == CrudStatus::Deleted, - }) .map(|link_entry_crud| LinksResult { address: link_entry_crud.0.link().target().clone(), headers: link_entry_crud.1.clone(), @@ -44,10 +39,8 @@ pub async fn get_link_add_entries<'a>( //get link add entries let links_result = await!(get_links( context.clone(), - link_args.entry_address.clone(), - link_args.link_type.clone(), - link_args.tag.clone(), - link_args.options.timeout.clone() + link_args, + GetLinksNetworkQuery::Links ))?; //iterate over link add entries diff --git a/core/src/workflows/get_links_count.rs b/core/src/workflows/get_links_count.rs index 1819ceafd3..04292cd5c6 100644 --- a/core/src/workflows/get_links_count.rs +++ b/core/src/workflows/get_links_count.rs @@ -1,4 +1,4 @@ -use crate::{context::Context, network::actions::get_links_count::get_links_count}; +use crate::{context::Context, network::{actions::get_links::get_links,query::{GetLinksNetworkQuery,GetLinksNetworkResult}}}; use holochain_core_types::error::HolochainError; use holochain_wasm_utils::api_serialization::get_links::{GetLinksArgs, GetLinksResultCount}; @@ -8,14 +8,17 @@ pub async fn get_link_result_count_workflow<'a>( context: Arc, link_args: &'a GetLinksArgs, ) -> Result { - let links_count = await!(get_links_count( + let links_result = await!(get_links( context, - link_args.entry_address.clone(), - link_args.link_type.clone(), - link_args.tag.clone(), - link_args.options.timeout.clone(), - link_args.options.status_request.clone() + link_args, + GetLinksNetworkQuery::Count ))?; + let links_count = match links_result + { + GetLinksNetworkResult::Count(count) => Ok(count), + _ => Err(HolochainError::ErrorGeneric("Getting wrong type of GetLinks".to_string())) + }?; + Ok(GetLinksResultCount { count: links_count }) } From 0f2d83b0c9615dff9b83cad39bd3eb4d9673b016 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Mon, 15 Jul 2019 13:22:58 -0400 Subject: [PATCH 38/48] cargo fmt --- core/src/action.rs | 12 +++--- core/src/network/actions/get_links.rs | 16 ++++---- core/src/network/handler/query.rs | 40 ++++++++----------- core/src/network/mod.rs | 17 ++++---- core/src/network/query.rs | 14 +++---- core/src/network/reducers/get_links.rs | 33 ++++++++++----- .../reducers/handle_get_links_result.rs | 4 +- .../src/network/reducers/respond_get_links.rs | 7 +++- core/src/network/state.rs | 7 ++-- core/src/nucleus/ribosome/api/remove_link.rs | 26 ++++++------ core/src/workflows/get_link_result.rs | 13 ++++-- core/src/workflows/get_links_count.rs | 21 +++++----- 12 files changed, 112 insertions(+), 98 deletions(-) diff --git a/core/src/action.rs b/core/src/action.rs index daf951bddd..8f38d0e7a6 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -1,9 +1,11 @@ use crate::{ agent::state::AgentState, network::{ - direct_message::DirectMessage, entry_aspect::EntryAspect, - entry_with_header::EntryWithHeader, state::NetworkState, - query::{GetLinksNetworkQuery,GetLinksNetworkResult} + direct_message::DirectMessage, + entry_aspect::EntryAspect, + entry_with_header::EntryWithHeader, + query::{GetLinksNetworkQuery, GetLinksNetworkResult}, + state::NetworkState, }, nucleus::{ actions::{call_zome_function::ExecuteZomeFnResponse, initialize::Initialization}, @@ -159,11 +161,11 @@ pub enum Action { /// get links from entry address and link_type name /// Last string is the stringified process unique id of this `hdk::get_links` call. - GetLinks((GetLinksKey,Option,GetLinksNetworkQuery)), + GetLinks((GetLinksKey, Option, GetLinksNetworkQuery)), GetLinksTimeout(GetLinksKey), RespondGetLinks((QueryEntryData, GetLinksNetworkResult, String, String)), HandleGetLinksResult((GetLinksNetworkResult, GetLinksKey)), - + /// Makes the network module send a direct (node-to-node) message /// to the address given in [DirectMessageData](struct.DirectMessageData.html) SendDirectMessage(DirectMessageData), diff --git a/core/src/network/actions/get_links.rs b/core/src/network/actions/get_links.rs index aed86fbfbc..4fbce3f807 100644 --- a/core/src/network/actions/get_links.rs +++ b/core/src/network/actions/get_links.rs @@ -2,18 +2,17 @@ use crate::{ action::{Action, ActionWrapper, GetLinksKey}, context::Context, instance::dispatch_action, - network::query::{GetLinksNetworkQuery,GetLinksNetworkResult} + network::query::{GetLinksNetworkQuery, GetLinksNetworkResult}, }; use futures::{ future::Future, task::{LocalWaker, Poll}, }; -use holochain_core_types::{error::HcResult,crud_status::CrudStatus}; +use holochain_core_types::{crud_status::CrudStatus, error::HcResult}; use snowflake::ProcessUniqueId; use std::{pin::Pin, sync::Arc, thread}; -use holochain_wasm_utils::api_serialization::get_links::{GetLinksArgs,LinksStatusRequestKind}; - +use holochain_wasm_utils::api_serialization::get_links::{GetLinksArgs, LinksStatusRequestKind}; /// GetLinks Action Creator /// This is the network version of get_links that makes the network module start @@ -21,7 +20,7 @@ use holochain_wasm_utils::api_serialization::get_links::{GetLinksArgs,LinksStatu pub async fn get_links( context: Arc, link_args: &GetLinksArgs, - query : GetLinksNetworkQuery + query: GetLinksNetworkQuery, ) -> HcResult { let key = GetLinksKey { base_address: link_args.entry_address.clone(), @@ -29,13 +28,12 @@ pub async fn get_links( tag: link_args.tag.clone(), id: ProcessUniqueId::new().to_string(), }; - let crud_status = match link_args.options.status_request - { + let crud_status = match link_args.options.status_request { LinksStatusRequestKind::All => None, LinksStatusRequestKind::Deleted => Some(CrudStatus::Deleted), - LinksStatusRequestKind::Live => Some(CrudStatus::Live) + LinksStatusRequestKind::Live => Some(CrudStatus::Live), }; - let action_wrapper = ActionWrapper::new(Action::GetLinks((key.clone(),crud_status,query))); + let action_wrapper = ActionWrapper::new(Action::GetLinks((key.clone(), crud_status, query))); dispatch_action(context.action_channel(), action_wrapper.clone()); let key_inner = key.clone(); diff --git a/core/src/network/handler/query.rs b/core/src/network/handler/query.rs index 0da2026193..8a3246a25b 100644 --- a/core/src/network/handler/query.rs +++ b/core/src/network/handler/query.rs @@ -3,7 +3,9 @@ use crate::{ context::Context, entry::CanPublish, instance::dispatch_action, - network::query::{NetworkQuery, NetworkQueryResult,GetLinksNetworkQuery,GetLinksNetworkResult}, + network::query::{ + GetLinksNetworkQuery, GetLinksNetworkResult, NetworkQuery, NetworkQueryResult, + }, nucleus, }; use holochain_core_types::{crud_status::CrudStatus, entry::EntryWithMetaAndHeader}; @@ -70,7 +72,7 @@ fn get_entry(context: &Arc, address: Address) -> Option) { let query_json = JsonString::from_json(&String::from_utf8(query_data.query.clone()).unwrap()); let action_wrapper = match query_json.clone().try_into() { - Ok(NetworkQuery::GetLinks(link_type, tag,options,query)) => { + Ok(NetworkQuery::GetLinks(link_type, tag, options, query)) => { let links = get_links( &context, query_data.entry_address.clone(), @@ -78,25 +80,17 @@ pub fn handle_query_entry_data(query_data: QueryEntryData, context: Arc tag.clone(), options, ); - let links_result = match query - { - GetLinksNetworkQuery::Links => - { - GetLinksNetworkResult::Links(links) - }, - GetLinksNetworkQuery::Count => - { - GetLinksNetworkResult::Count(links.len()) - } + let links_result = match query { + GetLinksNetworkQuery::Links => GetLinksNetworkResult::Links(links), + GetLinksNetworkQuery::Count => GetLinksNetworkResult::Count(links.len()), }; ActionWrapper::new(Action::RespondGetLinks(( - query_data, - links_result, - link_type.clone(), - tag.clone(), - ))) - + query_data, + links_result, + link_type.clone(), + tag.clone(), + ))) } Ok(NetworkQuery::GetEntry) => { let maybe_entry = get_entry(&context, query_data.entry_address.clone()); @@ -129,17 +123,15 @@ pub fn handle_query_entry_result(query_result_data: QueryEntryResultData, contex ))) } Ok(NetworkQueryResult::Links(links_result, link_type, tag)) => { - ActionWrapper::new(Action::HandleGetLinksResult(( - links_result, - GetLinksKey { + links_result, + GetLinksKey { base_address: query_result_data.entry_address.clone(), link_type: link_type.clone(), tag: tag.clone(), id: query_result_data.request_id.clone(), - }, - ))) - + }, + ))) } err => { context.log(format!( diff --git a/core/src/network/mod.rs b/core/src/network/mod.rs index 5a07b39963..7e37b5e802 100644 --- a/core/src/network/mod.rs +++ b/core/src/network/mod.rs @@ -19,8 +19,8 @@ pub mod tests { get_entry::get_entry, get_links::get_links, get_validation_package::get_validation_package, publish::publish, }, + query::{GetLinksNetworkQuery, GetLinksNetworkResult}, test_utils::test_wat_always_valid, - query::{GetLinksNetworkQuery,GetLinksNetworkResult} }, workflows::author_entry::author_entry, }; @@ -33,8 +33,8 @@ pub mod tests { }; use holochain_json_api::json::JsonString; use holochain_persistence_api::cas::content::{Address, AddressableContent}; - use test_utils::*; use holochain_wasm_utils::api_serialization::get_links::GetLinksArgs; + use test_utils::*; // TODO: Should wait for a success or saturation response from the network module after Publish #[test] @@ -291,17 +291,16 @@ pub mod tests { // std::thread::sleep(std::time::Duration::from_millis(1000)); println!("\n get_links() ..."); - let get_links_args = GetLinksArgs - { - entry_address : entry_addresses[0].clone(), - link_type : "test-link".into(), - tag : "test-tag".into(), - options : Default::default() + let get_links_args = GetLinksArgs { + entry_address: entry_addresses[0].clone(), + link_type: "test-link".into(), + tag: "test-tag".into(), + options: Default::default(), }; let maybe_links = context2.block_on(get_links( context2.clone(), &get_links_args, - GetLinksNetworkQuery::Links + GetLinksNetworkQuery::Links, )); assert!(maybe_links.is_ok()); diff --git a/core/src/network/query.rs b/core/src/network/query.rs index 4848a53394..f165056e67 100644 --- a/core/src/network/query.rs +++ b/core/src/network/query.rs @@ -3,27 +3,25 @@ use holochain_json_api::{error::JsonError, json::JsonString}; use holochain_persistence_api::cas::content::Address; #[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] -pub enum GetLinksNetworkQuery -{ +pub enum GetLinksNetworkQuery { Count, - Links + Links, } #[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] -pub enum GetLinksNetworkResult -{ +pub enum GetLinksNetworkResult { Count(usize), - Links(Vec<(Address, CrudStatus)>) + Links(Vec<(Address, CrudStatus)>), } #[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] pub enum NetworkQuery { GetEntry, - GetLinks(String, String,Option,GetLinksNetworkQuery), + GetLinks(String, String, Option, GetLinksNetworkQuery), } #[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)] pub enum NetworkQueryResult { Entry(Option), - Links(GetLinksNetworkResult,String,String) + Links(GetLinksNetworkResult, String, String), } diff --git a/core/src/network/reducers/get_links.rs b/core/src/network/reducers/get_links.rs index c65f8a9e99..046c75611b 100644 --- a/core/src/network/reducers/get_links.rs +++ b/core/src/network/reducers/get_links.rs @@ -1,10 +1,14 @@ use crate::{ action::{ActionWrapper, GetLinksKey}, - network::{query::{NetworkQuery,GetLinksNetworkQuery}, reducers::send, state::NetworkState}, + network::{ + query::{GetLinksNetworkQuery, NetworkQuery}, + reducers::send, + state::NetworkState, + }, state::State, }; -use holochain_core_types::{error::HolochainError,crud_status::CrudStatus}; +use holochain_core_types::{crud_status::CrudStatus, error::HolochainError}; use holochain_json_api::json::JsonString; use holochain_net::connection::json_protocol::{JsonProtocol, QueryEntryData}; use holochain_persistence_api::hash::HashString; @@ -12,12 +16,17 @@ use holochain_persistence_api::hash::HashString; fn reduce_get_links_inner( network_state: &mut NetworkState, key: &GetLinksKey, - get_links_query : &GetLinksNetworkQuery, - crud_status : &Option + get_links_query: &GetLinksNetworkQuery, + crud_status: &Option, ) -> Result<(), HolochainError> { network_state.initialized()?; - let query_json: JsonString = - NetworkQuery::GetLinks(key.link_type.clone(), key.tag.clone(),crud_status.clone(),get_links_query.clone()).into(); + let query_json: JsonString = NetworkQuery::GetLinks( + key.link_type.clone(), + key.tag.clone(), + crud_status.clone(), + get_links_query.clone(), + ) + .into(); send( network_state, JsonProtocol::QueryEntry(QueryEntryData { @@ -36,9 +45,9 @@ pub fn reduce_get_links( action_wrapper: &ActionWrapper, ) { let action = action_wrapper.action(); - let (key,crud_status,query) = unwrap_to!(action => crate::action::Action::GetLinks); + let (key, crud_status, query) = unwrap_to!(action => crate::action::Action::GetLinks); - let result = match reduce_get_links_inner(network_state, &key,&query,crud_status) { + let result = match reduce_get_links_inner(network_state, &key, &query, crud_status) { Ok(()) => None, Err(err) => Some(Err(err)), }; @@ -71,8 +80,8 @@ mod tests { use crate::{ action::{Action, ActionWrapper, GetLinksKey}, instance::tests::test_context, + network::query::GetLinksNetworkQuery, state::test_store, - network::query::GetLinksNetworkQuery }; use holochain_core_types::error::HolochainError; //use std::sync::{Arc, RwLock}; @@ -90,7 +99,11 @@ mod tests { tag: "link-tag".to_string(), id: snowflake::ProcessUniqueId::new().to_string(), }; - let action_wrapper = ActionWrapper::new(Action::GetLinks((key.clone(),None,GetLinksNetworkQuery::Links))); + let action_wrapper = ActionWrapper::new(Action::GetLinks(( + key.clone(), + None, + GetLinksNetworkQuery::Links, + ))); let store = store.reduce(action_wrapper); let maybe_get_links_result = store diff --git a/core/src/network/reducers/handle_get_links_result.rs b/core/src/network/reducers/handle_get_links_result.rs index 7647775528..eff675d63b 100644 --- a/core/src/network/reducers/handle_get_links_result.rs +++ b/core/src/network/reducers/handle_get_links_result.rs @@ -1,4 +1,4 @@ -use crate::{action::ActionWrapper, network::state::NetworkState,state::State}; +use crate::{action::ActionWrapper, network::state::NetworkState, state::State}; pub fn reduce_handle_get_links_result( network_state: &mut NetworkState, @@ -7,7 +7,7 @@ pub fn reduce_handle_get_links_result( ) { let action = action_wrapper.action(); let (links, key) = unwrap_to!(action => crate::action::Action::HandleGetLinksResult); - + network_state .get_links_results .insert(key.clone(), Some(Ok(links.clone()))); diff --git a/core/src/network/reducers/respond_get_links.rs b/core/src/network/reducers/respond_get_links.rs index d8d00e1e21..c022b20046 100644 --- a/core/src/network/reducers/respond_get_links.rs +++ b/core/src/network/reducers/respond_get_links.rs @@ -1,11 +1,14 @@ use crate::{ action::ActionWrapper, network::{ - actions::ActionResponse, query::{NetworkQueryResult,GetLinksNetworkResult}, reducers::send, state::NetworkState, + actions::ActionResponse, + query::{GetLinksNetworkResult, NetworkQueryResult}, + reducers::send, + state::NetworkState, }, state::State, }; -use holochain_core_types::{ error::HolochainError}; +use holochain_core_types::error::HolochainError; use holochain_json_api::json::JsonString; use holochain_net::connection::json_protocol::{ JsonProtocol, QueryEntryData, QueryEntryResultData, diff --git a/core/src/network/state.rs b/core/src/network/state.rs index acee63abe9..8e5a4da4ae 100644 --- a/core/src/network/state.rs +++ b/core/src/network/state.rs @@ -1,11 +1,12 @@ use crate::{ action::{ActionWrapper, GetEntryKey, GetLinksKey}, - network::{actions::ActionResponse, direct_message::DirectMessage,query::GetLinksNetworkResult}, + network::{ + actions::ActionResponse, direct_message::DirectMessage, query::GetLinksNetworkResult, + }, }; use boolinator::*; use holochain_core_types::{ - entry::EntryWithMetaAndHeader, error::HolochainError, - validation::ValidationPackage, + entry::EntryWithMetaAndHeader, error::HolochainError, validation::ValidationPackage, }; use holochain_net::p2p_network::P2pNetwork; use holochain_persistence_api::cas::content::Address; diff --git a/core/src/nucleus/ribosome/api/remove_link.rs b/core/src/nucleus/ribosome/api/remove_link.rs index e09c47154b..655a7816ab 100644 --- a/core/src/nucleus/ribosome/api/remove_link.rs +++ b/core/src/nucleus/ribosome/api/remove_link.rs @@ -1,5 +1,8 @@ use crate::{ - network::{actions::get_links::get_links,query::{GetLinksNetworkResult,GetLinksNetworkQuery}}, + network::{ + actions::get_links::get_links, + query::{GetLinksNetworkQuery, GetLinksNetworkResult}, + }, nucleus::ribosome::{api::ZomeApiResult, Runtime}, workflows::{author_entry::author_entry, get_entry_result::get_entry_result_workflow}, }; @@ -12,7 +15,7 @@ use holochain_core_types::{ }; use holochain_wasm_utils::api_serialization::{ get_entry::{GetEntryArgs, GetEntryOptions, GetEntryResultType}, - get_links::{GetLinksOptions,GetLinksArgs}, + get_links::{GetLinksArgs, GetLinksOptions}, link_entries::LinkEntriesArgs, }; use std::convert::TryFrom; @@ -58,28 +61,25 @@ pub fn invoke_remove_link(runtime: &mut Runtime, args: &RuntimeArgs) -> ZomeApiR top_chain_header, context.agent_id.clone(), ); - let get_links_args = GetLinksArgs - { - entry_address : link.base().clone(), - link_type : link.link_type().clone(), - tag : link.tag().clone(), - options: GetLinksOptions::default() - + let get_links_args = GetLinksArgs { + entry_address: link.base().clone(), + link_type: link.link_type().clone(), + tag: link.tag().clone(), + options: GetLinksOptions::default(), }; let links_result = context.block_on(get_links( context.clone(), &get_links_args, - GetLinksNetworkQuery::Links + GetLinksNetworkQuery::Links, )); if links_result.is_err() { context.log("err/zome : Could not get links for remove_link method"); ribosome_error_code!(WorkflowFailed) } else { let links = links_result.expect("This is supposed to not fail"); - let links = match links - { + let links = match links { GetLinksNetworkResult::Links(links) => links, - _ => return ribosome_error_code!(WorkflowFailed) + _ => return ribosome_error_code!(WorkflowFailed), }; let filtered_links = links .into_iter() diff --git a/core/src/workflows/get_link_result.rs b/core/src/workflows/get_link_result.rs index b5b12ceaa1..736a61b1e4 100644 --- a/core/src/workflows/get_link_result.rs +++ b/core/src/workflows/get_link_result.rs @@ -1,5 +1,9 @@ use crate::{ - context::Context, network::{actions::get_links::get_links,query::{GetLinksNetworkQuery,GetLinksNetworkResult}}, + context::Context, + network::{ + actions::get_links::get_links, + query::{GetLinksNetworkQuery, GetLinksNetworkResult}, + }, workflows::get_entry_result::get_entry_result_workflow, }; @@ -44,10 +48,11 @@ pub async fn get_link_add_entries<'a>( ))?; //iterate over link add entries - let links_caches = match links_result - { + let links_caches = match links_result { GetLinksNetworkResult::Links(links_caches) => Ok(links_caches), - _ => Err(HolochainError::ErrorGeneric("Should only get link caches".to_string())) + _ => Err(HolochainError::ErrorGeneric( + "Should only get link caches".to_string(), + )), }?; let (links_result, get_links_error): (Vec<_>, Vec<_>) = links_caches .iter() diff --git a/core/src/workflows/get_links_count.rs b/core/src/workflows/get_links_count.rs index 04292cd5c6..b871a16673 100644 --- a/core/src/workflows/get_links_count.rs +++ b/core/src/workflows/get_links_count.rs @@ -1,4 +1,10 @@ -use crate::{context::Context, network::{actions::get_links::get_links,query::{GetLinksNetworkQuery,GetLinksNetworkResult}}}; +use crate::{ + context::Context, + network::{ + actions::get_links::get_links, + query::{GetLinksNetworkQuery, GetLinksNetworkResult}, + }, +}; use holochain_core_types::error::HolochainError; use holochain_wasm_utils::api_serialization::get_links::{GetLinksArgs, GetLinksResultCount}; @@ -8,16 +14,13 @@ pub async fn get_link_result_count_workflow<'a>( context: Arc, link_args: &'a GetLinksArgs, ) -> Result { - let links_result = await!(get_links( - context, - link_args, - GetLinksNetworkQuery::Count - ))?; + let links_result = await!(get_links(context, link_args, GetLinksNetworkQuery::Count))?; - let links_count = match links_result - { + let links_count = match links_result { GetLinksNetworkResult::Count(count) => Ok(count), - _ => Err(HolochainError::ErrorGeneric("Getting wrong type of GetLinks".to_string())) + _ => Err(HolochainError::ErrorGeneric( + "Getting wrong type of GetLinks".to_string(), + )), }?; Ok(GetLinksResultCount { count: links_count }) From 168f4e20300280a3a6e3bf36fc22f20fdf26d566 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Mon, 15 Jul 2019 13:54:11 -0400 Subject: [PATCH 39/48] added case in test where different tag is added --- app_spec/test/test.js | 5 +++++ app_spec/zomes/simple/code/src/lib.rs | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index 2ee231345b..e6f7664734 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -859,6 +859,11 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { await alice.app.callSync("simple", "create_link", { "base": alice.app.agentId ,"target": "Holo world" } ); + + //commit an entry with other tag + await alice.app.callSync("simple", "create_link_with_tag", + { "base": alice.app.agentId ,"target": "Holo world", tag:"different tag" } +); const alice_result = await alice.app.callSync("simple", "create_link", { "base": alice.app.agentId ,"target": "Holo world 2" } diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index d2e532f134..50f0ebad50 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -54,13 +54,19 @@ fn simple_entry(content: String) -> Entry { pub fn handle_create_my_link(base: Address,target : String) -> ZomeApiResult<()> { let address = hdk::commit_entry(&simple_entry(target))?; - hdk::link_entries(&base, &HashString::from(address), "authored_simple_posts", "")?; + hdk::link_entries(&base, &HashString::from(address), "authored_simple_posts", "tag")?; + Ok(()) +} + +pub fn handle_create_my_link_with_tag(base: Address,target : String, tag : String) -> ZomeApiResult<()> { + let address = hdk::commit_entry(&simple_entry(target))?; + hdk::link_entries(&base, &HashString::from(address), "authored_simple_posts", tag)?; Ok(()) } pub fn handle_delete_my_link(base: Address,target : String) -> ZomeApiResult<()> { let address = hdk::entry_address(&simple_entry(target))?; - hdk::remove_link(&base, &HashString::from(address), "authored_simple_posts", "")?; + hdk::remove_link(&base, &HashString::from(address), "authored_simple_posts", "tag")?; Ok(()) } @@ -149,6 +155,11 @@ define_zome! { outputs: |result: ZomeApiResult<()>|, handler: handle_create_my_link } + create_link_with_tag: { + inputs: |base : Address,target:String,tag:String|, + outputs: |result: ZomeApiResult<()>|, + handler: handle_create_my_link_with_tag + } delete_link: { inputs: |base : Address,target:String|, outputs: |result: ZomeApiResult<()>|, From 59554e31fe3105e1112281608bfca5a732e4195c Mon Sep 17 00:00:00 2001 From: Purple Hair Rust Bard Date: Mon, 15 Jul 2019 18:22:26 -0400 Subject: [PATCH 40/48] Update lib.rs --- app_spec/zomes/simple/code/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index 0864e82e21..7685cd247b 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -59,7 +59,7 @@ pub fn handle_create_my_link(base: Address,target : String) -> ZomeApiResult<()> pub fn handle_create_my_link_with_tag(base: Address,target : String, tag : String) -> ZomeApiResult<()> { let address = hdk::commit_entry(&simple_entry(target))?; - hdk::link_entries(&base, &HashString::from(address), "authored_simple_posts", tag)?; + hdk::link_entries(&base, &HashString::from(address), "authored_simple_posts", &tag)?; Ok(()) } From 1617097c0d199ec8606a5322a70539bce6b36b62 Mon Sep 17 00:00:00 2001 From: Purple Hair Rust Bard Date: Mon, 15 Jul 2019 18:50:30 -0400 Subject: [PATCH 41/48] tigger cI --- app_spec/zomes/simple/code/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index 7685cd247b..dc7b59731e 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -65,7 +65,7 @@ pub fn handle_create_my_link_with_tag(base: Address,target : String, tag : Strin pub fn handle_delete_my_link(base: Address,target : String) -> ZomeApiResult<()> { let address = hdk::entry_address(&simple_entry(target))?; - hdk::remove_link(&base, &HashString::from(address), "authored_simple_posts", "tag")?; + hdk::remove_link(&base, &HashString::from(address), "authored_simple_posts","tag")?; Ok(()) } From bc566d4f38a56b8cbc07141c6237cf7b697b8a11 Mon Sep 17 00:00:00 2001 From: Purple Hair Rust Bard Date: Mon, 15 Jul 2019 18:59:37 -0400 Subject: [PATCH 42/48] Update test.js --- app_spec/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index e6f7664734..fdb316b4d6 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -862,7 +862,7 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { //commit an entry with other tag await alice.app.callSync("simple", "create_link_with_tag", - { "base": alice.app.agentId ,"target": "Holo world", tag:"different tag" } + { "base": alice.app.agentId ,"target": "Holo world", "tag":"different tag" } ); const alice_result = await alice.app.callSync("simple", "create_link", From 247338cac990fd5e8b19879ec4f6a0119262b17d Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 17 Jul 2019 08:43:07 -0400 Subject: [PATCH 43/48] changes to zome --- app_spec/zomes/simple/code/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index 50f0ebad50..fcd8ca680a 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -80,13 +80,13 @@ pub fn handle_get_my_links(agent : Address,status_request:Option) ->ZomeApiResult +pub fn handle_get_my_links_count(agent : Address,status_request:Option,tag:Option) ->ZomeApiResult { let options = GetLinksOptions{ status_request : status_request.unwrap_or(LinksStatusRequestKind::All), ..GetLinksOptions::default() }; - hdk::get_links_count_with_options(&agent, LinkMatch::Exactly("authored_simple_posts"), LinkMatch::Any,options) + hdk::get_links_count_with_options(&agent, LinkMatch::Exactly("authored_simple_posts"),tag.unwrap_or(LinkMatch::Exactly(tag)),options) } pub fn handle_test_emit_signal(message: String) -> ZomeApiResult<()> { @@ -171,7 +171,7 @@ define_zome! { handler: handle_get_my_links } get_my_links_count: { - inputs: |base: Address,status_request:Option|, + inputs: |base: Address,status_request:Option,tag:Option|, outputs: |result: ZomeApiResult|, handler: handle_get_my_links_count } From 6d0f1fc32739b6071ae7bbcdab0f706b605d0c2d Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 17 Jul 2019 09:37:15 -0400 Subject: [PATCH 44/48] changes to zome --- app_spec/zomes/simple/code/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index 6c08fdb7a2..a5e0e32174 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -79,13 +79,13 @@ pub fn handle_get_my_links(agent : Address,status_request:Option,tag:Option) ->ZomeApiResult +pub fn handle_get_my_links_count(agent : Address,status_request:Option,tag:String) ->ZomeApiResult { let options = GetLinksOptions{ status_request : status_request.unwrap_or(LinksStatusRequestKind::All), ..GetLinksOptions::default() }; - hdk::get_links_count_with_options(&agent, LinkMatch::Exactly("authored_simple_posts"),tag.unwrap_or(LinkMatch::Exactly(tag)),options) + hdk::get_links_count_with_options(&agent, LinkMatch::Exactly("authored_simple_posts"),LinkMatch::Exactly(&*tag),options) } pub fn handle_test_emit_signal(message: String) -> ZomeApiResult<()> { @@ -170,7 +170,7 @@ define_zome! { handler: handle_get_my_links } get_my_links_count: { - inputs: |base: Address,status_request:Option,tag:Option|, + inputs: |base: Address,status_request:Option,tag:String|, outputs: |result: ZomeApiResult|, handler: handle_get_my_links_count } From df3700ca264567cd5520dcbde9f756f427e1a095 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 17 Jul 2019 12:37:41 -0400 Subject: [PATCH 45/48] fixed app_spec --- app_spec/test/test.js | 51 ++++++++++++++------ app_spec/zomes/simple/code/src/lib.rs | 33 +++++++++++-- core/src/nucleus/ribosome/api/remove_link.rs | 4 +- 3 files changed, 66 insertions(+), 22 deletions(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index fdb316b4d6..a76e461bde 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -856,65 +856,86 @@ scenario('get_links_crud', async (s, t, { alice, bob }) => { scenario('get_links_crud_count', async (s, t, { alice, bob }) => { //commits an entry and creates two links for alice - await alice.app.callSync("simple", "create_link", - { "base": alice.app.agentId ,"target": "Holo world" } + await alice.app.callSync("simple", "create_link_with_tag", + { "base": alice.app.agentId ,"target": "Holo world","tag":"tag" } ); //commit an entry with other tag await alice.app.callSync("simple", "create_link_with_tag", - { "base": alice.app.agentId ,"target": "Holo world", "tag":"different tag" } -); + { "base": alice.app.agentId ,"target": "Holo world", "tag":"differen" } + ); - const alice_result = await alice.app.callSync("simple", "create_link", - { "base": alice.app.agentId ,"target": "Holo world 2" } - ); + await alice.app.callSync("simple", "create_link_with_tag", + { "base": alice.app.agentId ,"target": "Holo world 2","tag":"tag" }); //get posts for alice from alice const alice_posts_live= await alice.app.call("simple","get_my_links_count", { - "base" : alice.app.agentId,"status_request":"Live" + "base" : alice.app.agentId, + "status_request":"Live", + "tag":"tag" }) //get posts for alice from bob const bob_posts_live= await bob.app.call("simple","get_my_links_count", { "base" : alice.app.agentId, - "status_request":"Live" + "status_request":"Live", + "tag":"tag" }) - + + //make sure count equals to 2 t.equal(2,alice_posts_live.Ok.count); t.equal(2,bob_posts_live.Ok.count); + const bob_posts_live_diff_tag= await bob.app.call("simple","get_my_links_count", + { + "base" : alice.app.agentId, + "status_request":"Live", + "tag":"differen" + }) + + t.equal(1,bob_posts_live_diff_tag.Ok.count); + ////delete the holo world post from the links alice created - await alice.app.callSync("simple","delete_link", + await alice.app.callSync("simple","delete_link_with_tag", { "base" : alice.app.agentId, - "target" : "Holo world" + "target" : "Holo world", + "tag":"tag" }); //get all bob posts const bob_posts_deleted = await bob.app.call("simple","get_my_links_count", { "base" : alice.app.agentId, - "status_request" : "Deleted" + "status_request" : "Deleted", + "tag":"tag" }); // get all posts with a deleted status from alice const alice_posts_deleted = await alice.app.call("simple","get_my_links_count", { "base" : alice.app.agentId, - "status_request" : "Deleted" + "status_request" : "Deleted", + "tag":"tag" }); //make sure it is equal to 1 t.equal(1,alice_posts_deleted.Ok.count); t.equal(1,bob_posts_deleted.Ok.count); + const bob_posts_deleted_diff_tag= await bob.app.call("simple","get_my_links_count", + { + "base" : alice.app.agentId, + "status_request":"Live", + "tag":"differen" + }) - + t.equal(1,bob_posts_deleted_diff_tag.Ok.count); }) diff --git a/app_spec/zomes/simple/code/src/lib.rs b/app_spec/zomes/simple/code/src/lib.rs index a5e0e32174..9d7b4f3786 100644 --- a/app_spec/zomes/simple/code/src/lib.rs +++ b/app_spec/zomes/simple/code/src/lib.rs @@ -69,6 +69,12 @@ pub fn handle_delete_my_link(base: Address,target : String) -> ZomeApiResult<()> Ok(()) } +pub fn handle_delete_my_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()> { + let address = hdk::entry_address(&simple_entry(target))?; + hdk::remove_link(&base, &HashString::from(address), "authored_simple_posts",&tag)?; + Ok(()) +} + pub fn handle_get_my_links(agent : Address,status_request:Option) ->ZomeApiResult { @@ -79,10 +85,19 @@ pub fn handle_get_my_links(agent : Address,status_request:Option,tag:String) ->ZomeApiResult +pub fn handle_get_my_links_with_tag(agent : Address,status_request:LinksStatusRequestKind,tag:String) ->ZomeApiResult { let options = GetLinksOptions{ - status_request : status_request.unwrap_or(LinksStatusRequestKind::All), + status_request, + ..GetLinksOptions::default() + }; + hdk::get_links_with_options(&agent, LinkMatch::Exactly("authored_simple_posts"), LinkMatch::Exactly(&*tag),options) +} + +pub fn handle_get_my_links_count(agent : Address,status_request : LinksStatusRequestKind,tag:String) ->ZomeApiResult +{ + let options = GetLinksOptions{ + status_request, ..GetLinksOptions::default() }; hdk::get_links_count_with_options(&agent, LinkMatch::Exactly("authored_simple_posts"),LinkMatch::Exactly(&*tag),options) @@ -164,13 +179,23 @@ define_zome! { outputs: |result: ZomeApiResult<()>|, handler: handle_delete_my_link } + delete_link_with_tag: { + inputs: |base : Address,target:String,tag:String|, + outputs: |result: ZomeApiResult<()>|, + handler: handle_delete_my_link_with_tag + } get_my_links: { inputs: |base: Address,status_request:Option|, outputs: |result: ZomeApiResult|, handler: handle_get_my_links } + get_my_links_with_tag: { + inputs: |base: Address,status_request:LinksStatusRequestKind,tag:String|, + outputs: |result: ZomeApiResult|, + handler: handle_get_my_links_with_tag + } get_my_links_count: { - inputs: |base: Address,status_request:Option,tag:String|, + inputs: |base: Address,status_request:LinksStatusRequestKind,tag:String|, outputs: |result: ZomeApiResult|, handler: handle_get_my_links_count } @@ -192,7 +217,7 @@ define_zome! { ] traits: { - hc_public [create_link, delete_link, get_my_links, test_emit_signal,get_my_links_count,create_link_with_tag,get_my_links_count_by_tag,delete_link_with_tag,encrypt,decrypt] + hc_public [create_link, delete_link, get_my_links, test_emit_signal,get_my_links_count,create_link_with_tag,get_my_links_count_by_tag,delete_link_with_tag,get_my_links_with_tag,encrypt,decrypt] } } diff --git a/core/src/nucleus/ribosome/api/remove_link.rs b/core/src/nucleus/ribosome/api/remove_link.rs index 655a7816ab..7a8d9325ef 100644 --- a/core/src/nucleus/ribosome/api/remove_link.rs +++ b/core/src/nucleus/ribosome/api/remove_link.rs @@ -8,7 +8,6 @@ use crate::{ }; use holochain_core_types::{ - crud_status::CrudStatus, entry::Entry, error::HolochainError, link::{link_data::LinkData, LinkActionKind}, @@ -83,7 +82,6 @@ pub fn invoke_remove_link(runtime: &mut Runtime, args: &RuntimeArgs) -> ZomeApiR }; let filtered_links = links .into_iter() - .filter(|link_crud| link_crud.1 == CrudStatus::Live) .map(|link_crud| link_crud.0) .filter(|link_address| { context @@ -99,7 +97,7 @@ pub fn invoke_remove_link(runtime: &mut Runtime, args: &RuntimeArgs) -> ZomeApiR .entry .map(|entry| match entry { Entry::LinkAdd(link_data) => { - link_data.link().target() == link.target() + link_data.link().target() == link.target() } _ => false, }) From 04b6285f938df49caa69e22c7f654cd4b287d91b Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 17 Jul 2019 14:47:11 -0400 Subject: [PATCH 46/48] trigger CI --- app_spec/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index a76e461bde..d188df0dac 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -802,7 +802,7 @@ scenario('get_links_crud', async (s, t, { alice, bob }) => { t.equal("live",bob_posts_live.Ok.links[0].status); t.equal("live",bob_posts_live.Ok.links[1].status); - ////delete the holo world post from the links alice created + ////delete the holo world post from the links alice created. await alice.app.callSync("simple","delete_link", { "base" : alice.app.agentId, From d369c77bbaf39d4b1e877af5f06c225399b04541 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 17 Jul 2019 16:10:34 -0400 Subject: [PATCH 47/48] trigger CI --- app_spec/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index d188df0dac..a76e461bde 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -802,7 +802,7 @@ scenario('get_links_crud', async (s, t, { alice, bob }) => { t.equal("live",bob_posts_live.Ok.links[0].status); t.equal("live",bob_posts_live.Ok.links[1].status); - ////delete the holo world post from the links alice created. + ////delete the holo world post from the links alice created await alice.app.callSync("simple","delete_link", { "base" : alice.app.agentId, From 9645f52e7118ea7475ddfeeb36940d569f48e239 Mon Sep 17 00:00:00 2001 From: Ashanti Mutinta Date: Wed, 17 Jul 2019 16:49:09 -0400 Subject: [PATCH 48/48] trigger CI again --- app_spec/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_spec/test/test.js b/app_spec/test/test.js index a76e461bde..d9a9f455ad 100644 --- a/app_spec/test/test.js +++ b/app_spec/test/test.js @@ -924,7 +924,7 @@ scenario('get_links_crud_count', async (s, t, { alice, bob }) => { "tag":"tag" }); - //make sure it is equal to 1 + //make sure count is equal to 1 t.equal(1,alice_posts_deleted.Ok.count); t.equal(1,bob_posts_deleted.Ok.count);