hark-store: cleanup dangling unreads
Creates a noun poke %fix-dangling, which iterates through the unreads
and dismiss those which refer to nodes which no longer exist.
Additionally, adds a migration which runs this poke.
$% state:state-zero:store
state:state-one:store
state-2
+ state-3
==
+$ unread-stats
[indices=(set index:graph-store) last=@da]
::
-+$ state-2
- $: %2
- unreads-each=(jug stats-index:store index:graph-store)
++$ base-state
+ $: unreads-each=(jug stats-index:store index:graph-store)
unreads-count=(map stats-index:store @ud)
last-seen=(map stats-index:store @da)
=notifications:store
dnd=_|
==
::
++$ state-2
+ [%2 base-state]
+::
++$ state-3
+ [%3 base-state]
+::
+$ inflated-state
- $: state-2
+ $: state-3
cache
==
:: $cache: useful to have precalculated, but can be derived from state
=| cards=(list card)
|^
?- -.old
- %2
+ %3
:- cards
this(-.state old, +.state (inflate-cache:ha old))
+ ::
+ %2
+ %_ $
+ -.old %3
+ cards :_(cards [%pass / %agent [our dap]:bowl %poke noun+!>(%fix-dangling)])
+ ==
+
::
%1
%_ $
=^ cards state
?+ mark (on-poke:def mark vase)
%hark-action (hark-action !<(action:store vase))
- %noun ~& +.state [~ state]
+ %noun (poke-noun !<(* vase))
==
[cards this]
::
+ ++ poke-noun
+ |= val=*
+ ?+ val ~|(%bad-noun-poke !!)
+ %fix-dangling fix-dangling
+ %print ~&(+.state [~ state])
+ ==
+ ::
+ ++ fix-dangling
+ =/ graphs=(set resource)
+ get-keys:gra
+ :_ state
+ %+ roll
+ ~(tap by unreads-each)
+ |= $: [=stats-index:store indices=(set index:graph-store)]
+ out=(list card)
+ ==
+ ?. ?=(%graph -.stats-index) out
+ ?. (~(has in graphs) graph.stats-index)
+ :_(out (poke-us %remove-graph graph.stats-index))
+ %+ weld out
+ ^- (list card)
+ %+ turn
+ ^- (list index:graph-store)
+ %+ skip
+ `(list index:graph-store)`~(tap in indices)
+ |=(=index:graph-store (check-node-existence:gra graph.stats-index index))
+ |=(=index:graph-store (poke-us %read-each stats-index index))
+ ::
+ ++ poke-us
+ |= =action:store
+ ^- card
+ [%pass / %agent [our dap]:bowl %poke hark-action+!>(action)]
+ ::
++ hark-action
|= =action:store
^- (quip card _state)
==
::
++ inflate-cache
- |= state-2
+ |= state-3
^+ +.state
=/ nots=(list [p=@da =timebox:store])
(tap:orm notifications)
