graph-store: emit affected descended nodes in %remove-nodes

When %remove-nodes is sent as an update, it may refer to a parent node,
in which case the deletion of all the parent's children is implied. If
we hold onto references to nodes outside of graph-store, we are unable
to tell which of our references were affected, other than iterating over
every reference to check if one of the deleted indices is a prefix of
the reference. This is obviously undesirable, so we emit all of the
nodes we deleted, including the nodes deleted implicitly.
This commit is contained in:
Liam Fitzgerald 2021-01-11 11:50:11 +10:00
parent 18301fa7d7
commit 1ed0477663
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB

View File

@ -418,43 +418,83 @@
=/ =update-log:store (~(got by update-logs) resource)
=. update-log
(put:orm-log update-log time [%0 time [%remove-nodes resource indices]])
=/ [affected-indices=(set index:store) new-graph=graph:store]
(remove-indices resource graph (sort ~(tap in indices) by-lent))
::
:- (give [/updates]~ [%remove-nodes resource indices])
:- (give [/updates]~ [%remove-nodes resource (~(uni in indices) affected-indices)])
%_ state
update-logs (~(put by update-logs) resource update-log)
graphs
%+ ~(put by graphs)
resource
[(remove-indices resource graph ~(tap in indices)) mark]
[new-graph mark]
==
::
:: we always want to remove the deepest node first,
:: so we don't remove parents before children
++ by-lent
|* [a=(list) b=(list)]
^- ?
(gth (lent a) (lent b))
::
++ remove-indices
=| affected=(set index:store)
|= [=resource:store =graph:store indices=(list index:store)]
^- graph:store
?~ indices graph
^- [(set index:store) graph:store]
?~ indices [affected graph]
=^ new-affected graph
(remove-index graph i.indices)
%_ $
indices t.indices
graph (remove-index graph i.indices)
affected (~(uni in affected) new-affected)
==
::
++ get-descendants
|= =graph:store
=| indices=(list index:store)
=/ nodes=(list [atom node:store])
(tap:orm:store graph)
%- ~(gas in *(set index:store))
|- =* tap-nodes $
^+ indices
%- zing
%+ turn
nodes
|= [atom =node:store]
^- (list index:store)
%+ welp
(limo index.post.node ~)
?. ?=(%graph -.children.node)
~
%_ tap-nodes
nodes (tap:orm p.children.node)
==
::
++ remove-index
=| indices=(set index:store)
|= [=graph:store =index:store]
^- graph:store
?~ index graph
^- [_indices graph:store]
?~ index [indices graph]
=* atom i.index
:: last index in list
::
?~ t.index
+:`[* graph:store]`(del:orm graph atom)
=^ u-val graph (del:orm graph atom)
?~ u-val `graph
?. ?=(%graph -.children.u.u-val)
`graph
=/ new-indices
(get-descendants p.children.u.u-val)
[(~(uni in indices) new-indices) graph]
=/ =node:store
~| "parent index does not exist to remove a node from!"
(need (get:orm graph atom))
~| "child index does not exist to remove a node from!"
?> ?=(%graph -.children.node)
%^ put:orm
graph
atom
node(p.children $(graph p.children.node, index t.index))
=^ new-indices p.children.node
$(graph p.children.node, index t.index)
:- (~(uni in indices) new-indices)
(put:orm graph atom node)
--
::
++ add-signatures