From 31a84f583f5a48f879a8d8721c93cdcf21ac20b1 Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Tue, 4 May 2021 14:17:55 +1000 Subject: [PATCH] hark: refactor, add migration --- pkg/arvo/app/hark-store.hoon | 81 ++++---------- pkg/arvo/lib/hark/store.hoon | 199 +++++++++++++++++++++++++++++++++++ pkg/arvo/sur/hark-store.hoon | 2 +- 3 files changed, 220 insertions(+), 62 deletions(-) diff --git a/pkg/arvo/app/hark-store.hoon b/pkg/arvo/app/hark-store.hoon index b417d68e43..0cff474210 100644 --- a/pkg/arvo/app/hark-store.hoon +++ b/pkg/arvo/app/hark-store.hoon @@ -100,22 +100,25 @@ =| cards=(list card) |^ ^- (quip card _this) - ?+ -.old !! + ?- -.old %7 :- (flop cards) this(-.state old, +.state (inflate-cache:ha old)) - == :: - ++ unused - ?+ -.old !! - :: - %5 !! - :: %_ $ - ::-.old %6 - ::notifications.old (convert-notifications-4 notifications.old) - ::archive.old (convert-notifications-4 archive.old) - ::== - :: + %6 + %_ $ + -.old %7 + notifications.old (notifications:to-five:upgrade:store notifications.old) + archive.old ~ + == + :: + %5 + %_ $ + -.old %6 + notifications.old (notifications:to-four:upgrade:store notifications.old) + archive.old *notifications:state-four:store + == + :: %4 %_ $ -.old %5 @@ -124,14 +127,14 @@ %- ~(run by last-seen.old) |=(old=@da (min old now.bowl)) == - :: + :: %3 %_ $ -.old %4 notifications.old (convert-notifications-3 notifications.old) archive.old (convert-notifications-3 archive.old) == - :: + :: %2 %_ $ -.old %3 @@ -140,7 +143,7 @@ :_ cards [%pass / %agent [our dap]:bowl %poke noun+!>(%fix-dangling)] == - :: + :: %1 %_ $ :: @@ -155,7 +158,7 @@ dnd dnd.old == == - :: + :: %0 %_ $ :: @@ -169,50 +172,6 @@ == == :: - ++ convert-notifications-4 - |= old=notifications:state-three:store - %+ gas:orm:state-four:store *notifications:state-four:store - ^- (list [@da timebox:state-four:store]) - %+ murn - (tap:orm:state-three:store old) - |= [time=@da =timebox:state-three:store] - ^- (unit [@da timebox:state-four:store]) - =/ new-timebox=timebox:state-four:store - (convert-timebox-4 timebox) - ?: =(0 ~(wyt by new-timebox)) - ~ - `[time new-timebox] - :: - ++ convert-timebox-4 - |= =timebox:state-three:store - ^- timebox:state-four:store - %- ~(gas by *timebox:state-four:store) - ^- (list [index:state-four:store notification:state-four:store]) - %+ murn - ~(tap by timebox) - |= [=index:state-four:store =notification:state-three:store] - ^- (unit [index:state-four:store notification:state-four:store]) - =/ new-notification=(unit notification:state-four:store) - (convert-notification-4 notification) - ?~ new-notification ~ - `[index u.new-notification] - :: - ++ convert-notification-4 - |= =notification:state-three:store - ^- (unit notification:state-four:store) - ?: ?=(%group -.contents.notification) - `notification - =/ con=(list post:post) - (convert-graph-contents-4 list.contents.notification) - ?: =(~ con) ~ - =, notification - `[date read %graph con] - :: - ++ convert-graph-contents-4 - |= con=(list post:post-zero:post) - ^- (list post:post) - (turn con post-to-one:upgrade:graph-store) - :: ++ convert-notifications-3 |= old=notifications:state-two:store %+ gas:orm:state-three:store *notifications:state-three:store @@ -321,7 +280,7 @@ :: %graph =, index - `[%graph *resource *resource module description ~] + `[%graph graph *resource module description ~] == :: ++ convert-notification-1 diff --git a/pkg/arvo/lib/hark/store.hoon b/pkg/arvo/lib/hark/store.hoon index 0766dd6e8d..f76158055e 100644 --- a/pkg/arvo/lib/hark/store.hoon +++ b/pkg/arvo/lib/hark/store.hoon @@ -4,6 +4,205 @@ =< [. sur] =, sur |% +++ upgrade + |% + ++ to-four + =* three state-three + =* four state-four + |% + ++ index + |= =index:three + ^- (unit index:four) + `index + ++ contents + |= =contents:three + ^- (unit contents:four) + ?. ?=(%graph -.contents) + `contents + `[%graph (turn list.contents post-to-one:upgrade:graph-store)] + :: + ++ unreads-each + upg-unreads-each:upg + :: + ++ notifications + upg-notifications:upg + :: + ++ stats-index + |= =stats-index:three + ^- (unit stats-index:four) + `stats-index + :: + ++ upg + %. [index stats-index contents] + %: upgrade + index:three + stats-index:three + contents:three + index:four + stats-index:four + contents:four + == + -- + :: + ++ to-five + =* four state-four + =* five sur + |% + ++ mark + |= module=@t + ^- (unit @t) + ?+ module ~ + %chat `%graph-validator-chat + %publish `%graph-validator-publish + %link `%graph-validator-link + == + ++ index + |= =index:four + ^- (unit index:five) + ?: ?=(%group -.index) + `index + =* i index + `[%graph graph.i (mark module.i) description.i index.i] + :: + ++ contents + |= =contents:four + ^- (unit contents:five) + `contents + :: + ++ unreads-each + upg-unreads-each:upg + :: + ++ stats-index + |= =stats-index:four + ^- (unit stats-index:five) + `stats-index + :: + ++ upg + %. [index stats-index contents] + %: upgrade + index:four + stats-index:four + contents:four + index:five + stats-index:five + contents:five + == + + ++ notifications + upg-notifications:upg + -- + :: + ++ upgrade + |* $: :: input molds + in-index=mold + in-stats-index=mold + in-contents=mold + :: output molds + out-index=mold + out-stats-index=mold + out-contents=mold + == + => . => + |% + :: + ++ in + |% + :: + +$ index in-index + +$ stats-index in-stats-index + +$ contents in-contents + +$ unreads-each (jug stats-index index) + +$ timebox (map index notification) + +$ notification + [date=@da read=? =contents] + ++ orm + ((ordered-map time timebox) gth) + +$ notifications + ((mop time timebox) gth) + -- + ++ out + |% + :: + :: + +$ index out-index + +$ stats-index out-stats-index + +$ contents out-contents + +$ timebox (map out-index notification) + +$ unreads-each (jug stats-index index) + +$ notification + [date=@da read=? contents=out-contents] + +$ notifications + ((mop time timebox) gth) + ++ orm + ((ordered-map time timebox) gth) + -- + -- + |= $: fun-index=$-(index:in (unit index:out)) + fun-stats-index=$-(stats-index:in (unit stats-index:out)) + fun-contents=$-(contents:in (unit contents:out)) + == + |% + :: + ++ upg-unreads-each + |= =unreads-each:in + ^- unreads-each:out + %- ~(gas by *unreads-each:out) + %+ murn ~(tap by unreads-each) + |= [=stats-index:in indices=(set index:in)] + ^- (unit [stats-index:out (set index:out)]) + =/ new-stats + (fun-stats-index stats-index) + ?~ new-stats ~ + =/ new-indices + (upg-indices indices) + ?: =(0 ~(wyt ^in new-indices)) ~ + `[u.new-stats new-indices] + :: + ++ upg-indices + |= indices=(set index:in) + ^- (set index:out) + %- ~(gas ^in *(set index:out)) + (murn ~(tap ^in indices) fun-index) + :: + ++ upg-notifications + |= =notifications:in + ^- notifications:out + %+ gas:orm:out *notifications:out + ^- (list [@da timebox:out]) + %+ murn (tap:orm:in notifications) + |= [time=@da =timebox:in] + ^- (unit [@da =timebox:out]) + =/ new-timebox=timebox:out + (upg-timebox timebox) + ?: =(0 ~(wyt by timebox)) + ~ + `[time new-timebox] + :: + ++ upg-timebox + |= =timebox:in + ^- timebox:out + %- ~(gas by *timebox:out) + %+ murn ~(tap by timebox) + |= [=index:in =notification:in] + ^- (unit [index:out notification:out]) + =/ new-index + (fun-index index) + ?~ new-index ~ + =/ new-notification + (upg-notification notification) + ?~ new-notification ~ + `[u.new-index u.new-notification] + :: + ++ upg-notification + |= n=notification:in + ^- (unit notification:out) + =/ new-contents + (fun-contents contents.n) + ?~ new-contents ~ + `[date.n read.n u.new-contents] + -- + -- + ++ dejs =, dejs:format |% diff --git a/pkg/arvo/sur/hark-store.hoon b/pkg/arvo/sur/hark-store.hoon index 1e5097157d..e95a91e4ea 100644 --- a/pkg/arvo/sur/hark-store.hoon +++ b/pkg/arvo/sur/hark-store.hoon @@ -227,7 +227,7 @@ ((ordered-map @da timebox) gth) :: +$ base-state - $: unreads-each=(jug stats-index index) + $: unreads-each=(jug stats-index index:graph-store) unreads-count=(map stats-index @ud) last-seen=(map stats-index @da) =notifications