Skip to content

Commit

Permalink
Merge pull request #3124 from tloncorp/ns/trim-migration-state
Browse files Browse the repository at this point in the history
Trim migration state
  • Loading branch information
arthyn authored Jan 9, 2024
2 parents 67d5db6 + 8a41cce commit 419baac
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 12 deletions.
42 changes: 30 additions & 12 deletions desk/app/channels-server.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
|%
+$ card card:agent:gall
+$ current-state
$: %2
$: %3
=v-channels:c
==
--
Expand Down Expand Up @@ -86,12 +86,19 @@
=+ !<(old=versioned-state vase)
=? old ?=(%0 -.old) (state-0-to-1 old)
=? old ?=(%1 -.old) (state-1-to-2 old)
?> ?=(%2 -.old)
=? cor ?=(%2 -.old) (emit %pass /trim %agent [our.bowl %chat] %poke %chat-trim !>(~))
=? old ?=(%2 -.old) (state-2-to-3 old)
?> ?=(%3 -.old)
=. state old
inflate-io
::
+$ versioned-state $%(state-2 state-1 state-0)
+$ state-2 current-state
+$ versioned-state $%(state-3 state-2 state-1 state-0)
+$ state-3 current-state
+$ state-2 [%2 =v-channels:c]
++ state-2-to-3
|= old=state-2
^- state-3
[%3 +.old]
::
:: %1 to %2
::
Expand Down Expand Up @@ -204,17 +211,15 @@
^+ cor
=. cor
%- emil
%- turn :_ |=(=note:agent:gall [%pass /migrate note])
^- (list note:agent:gall)
:~ [%agent [our.bowl %diary] %poke %diary-migrate-server !>(~)]
[%agent [our.bowl %heap] %poke %heap-migrate-server !>(~)]
[%agent [our.bowl %chat] %poke %chat-migrate-server !>(~)]
:~ [%pass /migrate %agent [our.bowl %diary] %poke %diary-migrate-server !>(~)]
[%pass /migrate %agent [our.bowl %heap] %poke %heap-migrate-server !>(~)]
[%pass /migrate %agent [our.bowl %chat] %poke %chat-migrate-server !>(~)]
::NOTE we do these here and not in /app/channels, because it's
:: important that the server migration happens first, so that
:: the client migration may successfully establish subscriptions.
[%agent [our.bowl %diary] %poke %diary-migrate !>(~)]
[%agent [our.bowl %heap] %poke %heap-migrate !>(~)]
[%agent [our.bowl %chat] %poke %chat-migrate !>(~)]
[%pass /migrate %agent [our.bowl %diary] %poke %diary-migrate !>(~)]
[%pass /migrate %agent [our.bowl %heap] %poke %heap-migrate !>(~)]
[%pass /migrate/final %agent [our.bowl %chat] %poke %chat-migrate !>(~)]
==
inflate-io
::
Expand Down Expand Up @@ -325,6 +330,19 @@
%- (slog 'channels-server: migration poke failure' >wire< u.p.sign)
cor
==
[%migrate %final ~]
?+ -.sign !!
%poke-ack
?~ p.sign
(emit %pass /trim %agent [our.bowl %chat] %poke %chat-trim !>(~))
%- (slog 'channels-server: migration poke failure' >wire< u.p.sign)
cor
==
[%trim ~]
?+ -.sign !!
%poke-ack
cor
==
==
::
++ watch-groups (safe-watch /groups [our.bowl %groups] /groups)
Expand Down
48 changes: 48 additions & 0 deletions desk/app/chat.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@
?> from-self
=+ !<(flag=[ship term] vase)
(refs:migrate flag)
%chat-trim
?> from-self
trim:migrate
:: backwards compatibility
::
%dm-rsvp
Expand Down Expand Up @@ -902,6 +905,51 @@
!>(`a-channels:d`[%channel [%chat flag] %post u.command])
`[%pass /migrate %agent [our.bowl %channels] %poke cage]
::
++ trim
=- =. old-chats - cor
^- (map flag:two:old:c chat:two:old:c)
%- ~(run by old-chats)
|= old-chat=chat:two:old:c
=/ citations=(set [ship time])
%- sy
^- (list [ship time])
%- zing
^- (list (list [ship time]))
%+ murn (tap:on:writs:old wit.pact.old-chat)
|= [=time =writ:old]
^- (unit (list [ship ^time]))
:: return citer message and cited message
?. =(our.bowl author.writ) ~
=/ cite-targets=(list [ship ^time])
?. ?=(%story -.content.writ) ~
%+ murn p.p.content.writ
|= =block:old
^- (unit [ship ^time])
?. ?=([%cite %chan [%chat *] *] block) ~
?. ?=([%msg @ @ ~] wer.cite.block) ~
=/ who (slaw %p i.t.wer.cite.block)
?~ who ~
=/ tim (slaw %ud i.t.t.wer.cite.block)
?~ tim ~
`[u.who u.tim]
?~ cite-targets
~
`[id.writ cite-targets]
%= old-chat
log ~
dex.pact
%- malt
%+ murn ~(tap by dex.pact.old-chat)
|= [=id:old =time]
?. (~(has in citations) id) ~
`[id time]
wit.pact
%- malt
%+ murn (tap:on:writs:old wit.pact.old-chat)
|= [=time =writ:old]
?. (~(has in citations) id.writ) ~
`[time writ]
==
++ convert-pin
|= =whom:t
^- whom:u
Expand Down

0 comments on commit 419baac

Please sign in to comment.