Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Add dynamic link tagging #1402

Merged
merged 54 commits into from
May 22, 2019
Merged

Add dynamic link tagging #1402

merged 54 commits into from
May 22, 2019

Conversation

willemolding
Copy link
Collaborator

@willemolding willemolding commented May 14, 2019

PR summary

Depends on #1412

This PR adds tags to links with the following properties:

  • All links must have a tag
  • The tag of a link will be retrieved when hdk::get_links is called
  • It is possible to only get links that exactly match a given tag
  • It is possible to retrieve all links irrespective of the tag (and it will return all the tags)

Works great except introduced some flaky tests which need sorting out before merging. It is ready for review though

@willemolding willemolding added the WIP work in progress label May 14, 2019
core/src/action.rs Outdated Show resolved Hide resolved
]),
EavFilter::predicate(move |attr| {
match attr {
Attribute::LinkTag(query_link_type, query_tag) | Attribute::RemovedLink(query_link_type, query_tag) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Highlight: This is where filtering is done based on if a tag is provided (so match both tag and type) or only a type is provided (return all tags of that type)

@@ -17,11 +17,13 @@ use std::{pin::Pin, sync::Arc, thread};
pub async fn get_links(
context: Arc<Context>,
address: Address,
tag: String,
link_type: String,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I guess we also want this to be an Option

Suggested change
link_type: String,
link_type: Option<String>,

so that we could requests all links with the same tag but different types. That would match the get_links semantic we had in proto, no?
@zippy

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you think we should make link_type optional as well? I guess this is possible but not sure if it makes sense...

I am also not sure if we should be forcing every link to be tagged. This is how it works currently but I suppose we could let people pass a None to link_entries and have the HDK add a sensible default behind the scenes. There are a few usability things to sort out.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it makes sense to have no tag, i.e. None.

It does make sense to have the type optional in the get_links signature so that we can requests all links with the same tag but from different types.

Imagine a use-case where agents can add all different kinds of comments on entries, each being a link with a tag comment. But the reason why that comment is a valid statement could differ which would best be modeled by having multiple link types with different validation rules. But for rendering all those comments a UI might not care about why something is a valid comment, not caring for the type but instead requesting any link with the tag comment independent of the type.

Copy link
Collaborator

@lucksus lucksus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

But: the changelog is off and I would really love to see a test that shows getting links with a given tag works as expected (when there are multiple links with different tags).

CHANGELOG-UNRELEASED.md Show resolved Hide resolved
@willemolding
Copy link
Collaborator Author

Added the ability to retrieve based on type, tag, type+tag or everything.

Also added a test for getting the exact match tag (then there are other links to filter out) in the app spec and rust tests

@willemolding willemolding requested a review from lucksus May 21, 2019 02:25
@@ -6,12 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Option to show NPM output when pulling deps during `hc test` [PR#1401](https://github.com/holochain/holochain-rust/pull/1401)
- Adds scaffolding/skeleton for a future WASM conductor [#894](https://github.com/holochain/holochain-rust/pull/894)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines must stay in! Changelogs from other PRs that got merged before!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll get it right one day 🤦‍♂️

Copy link
Collaborator

@lucksus lucksus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have put back the changelog items you removed by mistake, see 40f6df8.

Looks great now!

Copy link
Member

@zippy zippy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Marking approved, though needs a few updates to docs and comments!

CHANGELOG-UNRELEASED.md Outdated Show resolved Hide resolved
core_types/src/link/mod.rs Outdated Show resolved Hide resolved
core/src/network/state.rs Outdated Show resolved Hide resolved
doc/holochain_101/src/first_steps.md Outdated Show resolved Hide resolved
doc/holochain_101/src/first_steps.md Outdated Show resolved Hide resolved
doc/holochain_101/src/zome/api_functions.md Outdated Show resolved Hide resolved
doc/holochain_101/src/zome/api_functions.md Outdated Show resolved Hide resolved
hdk-rust/src/api/get_links.rs Outdated Show resolved Hide resolved
hdk-rust/src/api/link_entries.rs Show resolved Hide resolved
@willemolding willemolding merged commit 76a8d2b into develop May 22, 2019
@@ -41,6 +42,7 @@ impl Default for GetLinksOptions {
pub struct LinksResult {
pub address: Address,
pub headers: Vec<ChainHeader>,
pub tag: String,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realise I'm late to the game here, but now that the link_type param in get_links is an Option, should LinksResult also include the link type?

@zippy zippy deleted the add-dynamic-link-tag-core branch October 4, 2019 18:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants