From 22d1348e5704ec811b81a9cb77aff28258133a90 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Wed, 24 Feb 2021 12:25:53 -0600 Subject: [PATCH] graph-push-hook: implement transform-add-nodes mark and properly ingest %add-nodes event --- pkg/arvo/app/graph-push-hook.hoon | 65 +++++++++++++++++------ pkg/arvo/mar/graph/validator/chat.hoon | 5 +- pkg/arvo/mar/graph/validator/link.hoon | 12 ++++- pkg/arvo/mar/graph/validator/publish.hoon | 20 ++++++- 4 files changed, 80 insertions(+), 22 deletions(-) diff --git a/pkg/arvo/app/graph-push-hook.hoon b/pkg/arvo/app/graph-push-hook.hoon index f01a7724d..5756788c2 100644 --- a/pkg/arvo/app/graph-push-hook.hoon +++ b/pkg/arvo/app/graph-push-hook.hoon @@ -76,34 +76,67 @@ %add-nodes ?. (is-allowed-add:hc rid nodes.q.update) ~ - :: TODO: use marks to transform based on graph-type =/ mark (get-mark:gra rid) ?~ mark `vas |^ - =/ transform=$-([index:store post:store] [index:store post:store]) - !< $-([index:store post:store] [index:store post:store]) + =/ transform=$-([index:store post:store atom ?] [index:store post:store]) + !< $-([index:store post:store atom ?] [index:store post:store]) %. !>(*indexed-post:store) .^(tube:clay (scry:hc %cc %home /[u.mark]/transform-add-nodes)) - =. nodes.q.update - %- ~(gas by *(map index:store node:store)) - %- zing - %+ turn - ~(tap by nodes.q.update) + =/ [* lis=(list [index:store node:store])] + %+ roll + (flatten-node-map ~(tap by nodes.q.update)) (transform-list transform) + =. nodes.q.update + (~(gas by *(map index:store node:store)) lis) [~ !>(update)] :: - ++ transform-list - |= transform=$-([index:store post:store] [index:store post:store]) + ++ flatten-node-map + |= lis=(list [index:store node:store]) + ^- (list [index:store node:store]) + |^ + %- sort-nodes + %+ weld + (turn lis empty-children) + %- zing + %+ turn lis |= [=index:store =node:store] ^- (list [index:store node:store]) - =/ [ind=index:store =post:store] (transform index post.node) - :- [ind [post [%empty ~]]] ?: ?=(%empty -.children.node) ~ - %- zing - %+ turn - (tap-deep:gra p.children.node) - (transform-list transform) + (turn (tap-deep:gra p.children.node) empty-children) + :: + ++ empty-children + |= [=index:store =node:store] + ^- [index:store node:store] + [index node(children [%empty ~])] + :: + ++ sort-nodes + |= lis=(list [index:store node:store]) + ^- (list [index:store node:store]) + %+ sort lis + |= [p=[=index:store *] q=[=index:store *]] + ^- ? + (lth (lent index.p) (lent index.q)) + -- + :: + ++ transform-list + |= transform=$-([index:store post:store atom ?] [index:store post:store]) + |= $: [=index:store =node:store] + [indices=(set index:store) lis=(list [index:store node:store])] + == + =/ l (lent index) + =/ parent-modified=? + %- ~(rep in indices) + |= [i=index:store out=?] + ?: out out + ?: (lte l (lent i)) + %.n + =((swag [0 l] i) index) + =/ [ind=index:store =post:store] + (transform index post.node now.bowl parent-modified) + :- (~(put in indices) index) + (snoc lis [ind node(post post)]) -- :: %remove-nodes diff --git a/pkg/arvo/mar/graph/validator/chat.hoon b/pkg/arvo/mar/graph/validator/chat.hoon index d843ec2f3..f80054cd6 100644 --- a/pkg/arvo/mar/graph/validator/chat.hoon +++ b/pkg/arvo/mar/graph/validator/chat.hoon @@ -22,9 +22,10 @@ == :: ++ transform-add-nodes - |= [=index =post] + |= [=index =post =atom was-parent-modified=?] ^- [^index ^post] - [index post] + =- [- post(index -)] + [atom ~] -- ++ grab |% diff --git a/pkg/arvo/mar/graph/validator/link.hoon b/pkg/arvo/mar/graph/validator/link.hoon index 717a33c2f..3d93723fe 100644 --- a/pkg/arvo/mar/graph/validator/link.hoon +++ b/pkg/arvo/mar/graph/validator/link.hoon @@ -32,9 +32,17 @@ == :: ++ transform-add-nodes - |= [=index =post] + |= [=index =post =atom was-parent-modified=?] ^- [^index ^post] - [index post] + =- [- post(index -)] + ?+ index ~|(transform+[index post] !!) + [@ ~] [atom ~] + [@ @ ~] [i.index atom ~] + [@ @ @ ~] + ?: was-parent-modified + [i.index atom atom ~] + [i.index i.t.index atom ~] + == -- ++ grab |% diff --git a/pkg/arvo/mar/graph/validator/publish.hoon b/pkg/arvo/mar/graph/validator/publish.hoon index 72262f4d2..b2511c245 100644 --- a/pkg/arvo/mar/graph/validator/publish.hoon +++ b/pkg/arvo/mar/graph/validator/publish.hoon @@ -32,9 +32,25 @@ == :: ++ transform-add-nodes - |= [=index =post] + |= [=index =post =atom was-parent-modified=?] ^- [^index ^post] - [index post] + =- [- post(index -)] + ?+ index ~|(transform+[index post] !!) + [@ ~] [atom ~] + [@ %1 ~] [atom %1 ~] + :: + [@ %1 @ ~] + ?: was-parent-modified + [atom %1 atom ~] + [i.index %1 atom ~] + :: + [@ %2 ~] [atom %2 ~] + [@ %2 @ ~] [i.index %2 atom ~] + [@ %2 @ @ ~] + ?: was-parent-modified + [i.index %2 atom atom ~] + [i.index %2 i.t.t.index atom ~] + == -- ++ grab |%