Skip to content

Commit

Permalink
Merge pull request #3847 from tloncorp/hm/store-logs-for-changes-endp…
Browse files Browse the repository at this point in the history
…oint

channels: store updated times for changes endpoint
  • Loading branch information
arthyn authored Aug 21, 2024
2 parents 18fc4b6 + ec11e8b commit d3ffe77
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 51 deletions.
29 changes: 23 additions & 6 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
$: %5
$: %6
=v-channels:c
=pimp:imp
==
Expand Down Expand Up @@ -91,15 +91,32 @@
=? old ?=(%2 -.old) (state-2-to-3 old)
=? old ?=(%3 -.old) (state-3-to-4 old)
=? old ?=(%4 -.old) (state-4-to-5 old)
?> ?=(%5 -.old)
=? old ?=(%5 -.old) (state-5-to-6 old)
?> ?=(%6 -.old)
=. state old
inflate-io
::
+$ versioned-state $%(state-5 state-4 state-3 state-2 state-1 state-0)
+$ state-5 current-state
+$ versioned-state $%(state-6 state-5 state-4 state-3 state-2 state-1 state-0)
+$ state-6 current-state
+$ state-5
$: %5
=v-channels:v6:old:c
=pimp:imp
==
++ state-5-to-6
|= state-5
^- state-6
[%6 (v-channels-5-to-6 v-channels) pimp]
++ v-channels-5-to-6
|= vc=v-channels:v6:old:c
^- v-channels:c
%- ~(run by vc)
|= v=v-channel:v6:old:c
^- v-channel:c
v(pending [pending.v *last-updated:c])
+$ state-4
$: %4
=v-channels:c
=v-channels:v6:old:c
==
++ state-4-to-5
|= state-4
Expand All @@ -113,7 +130,7 @@
::
++ v-channel-2-to-3
|= v=v-channel-2
^- v-channel:c
^- v-channel:v6:old:c
v(future [future.v *pending-messages:c])
++ v-channels-2 (map nest:c v-channel-2)
++ v-channel-2
Expand Down
143 changes: 98 additions & 45 deletions desk/app/channels.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:: performance, keep warm
/+ channel-json
::
=/ verbose |
%- %- agent:neg
:+ notify=&
[~.channels^%1 ~ ~]
Expand All @@ -27,7 +28,7 @@
|%
+$ card card:agent:gall
+$ current-state
$: %6
$: %7
=v-channels:c
voc=(map [nest:c plan:c] (unit said:c))
hidden-posts=(set id-post:c)
Expand Down Expand Up @@ -99,6 +100,11 @@
++ emil |=(caz=(list card) cor(cards (welp (flop caz) cards)))
++ give |=(=gift:agent:gall (emit %give gift))
++ server (cat 3 dap.bowl '-server')
++ log
|= msg=(trap tape)
?. verbose same
(slog leaf+"%{(trip dap.bowl)} {(msg)}" ~)
::
::
:: does not overwite if wire and dock exist. maybe it should
:: leave/rewatch if the path differs?
Expand All @@ -122,15 +128,48 @@
=? old ?=(%3 -.old) (state-3-to-4 old)
=? old ?=(%4 -.old) (state-4-to-5 old)
=? old ?=(%5 -.old) (state-5-to-6 old)
?> ?=(%6 -.old)
=? old ?=(%6 -.old) (state-6-to-7 old)
?> ?=(%7 -.old)
=. state old
inflate-io
::
+$ versioned-state $%(state-6 state-5 state-4 state-3 state-2 state-1 state-0)
+$ state-6 current-state
+$ versioned-state
$% state-7
state-6
state-5
state-4
state-3
state-2
state-1
state-0
==
+$ state-7 current-state
+$ state-6
$: %6
=v-channels:v6:old:c
voc=(map [nest:c plan:c] (unit said:c))
hidden-posts=(set id-post:c)
::
:: .pending-ref-edits: for migration, see also +poke %negotiate-notif
::
pending-ref-edits=(jug ship [=kind:c name=term])
:: delayed resubscribes
=^subs:s
=pimp:imp
==
++ state-6-to-7
|= s=state-6
^- state-7
s(- %7, v-channels (v-channels-6-to-7 v-channels.s))
++ v-channels-6-to-7
|= vc=v-channels:v6:old:c
^- v-channels:c
%- ~(run by vc)
|= v=v-channel:v6:old:c
v(pending [pending.v *last-updated:c])
+$ state-5
$: %5
=v-channels:c
=v-channels:v6:old:c
voc=(map [nest:c plan:c] (unit said:c))
hidden-posts=(set id-post:c)
::
Expand All @@ -148,7 +187,7 @@
::
+$ state-4
$: %4
=v-channels:c
=v-channels:v6:old:c
voc=(map [nest:c plan:c] (unit said:c))
pins=(list nest:c)
hidden-posts=(set id-post:c)
Expand Down Expand Up @@ -261,7 +300,7 @@
==
++ v-channel-2-to-3
|= v=v-channel-2
^- v-channel:c
^- v-channel:v6:old:c
v(future [future.v *pending-messages:c])
++ v-channel-1-to-2
|= v=v-channel-1
Expand Down Expand Up @@ -1304,6 +1343,16 @@
|= [=time =u-channel:c]
?> ca-from-host
^+ ca-core
=? last-updated.channel ?=(%post -.u-channel)
=/ id id.u-channel
=- (put:updated-on:c - time id.u-channel)
:: delete old entry so we don't have two entries for the same post
%+ gas:updated-on:c *last-updated:c
%+ murn
(tap:updated-on:c last-updated.channel)
|= [=^time =id-post:c]
?: =(id id-post) ~
`[time id-post]
?- -.u-channel
%create
?. =(0 rev.perm.channel) ca-core
Expand Down Expand Up @@ -1946,54 +1995,58 @@
%v2 give-posts-2
==
::
[%changes before=@ limit=@ ~]
=/ before=id-post:c
?^ tim=(slaw %da before.pole) u.tim
(slav %ud before.pole)
=/ limit=@ud ::$@([%count @ud] [%time @da]) ::TODO support?
:: ?^ tim=(slaw %da limit.pole) [%time u.tim]
:: [%count (slav %ud limit.pole)]
(slav %ud limit.pole)
=; [older=(unit time) posts=v-posts:c]
[%changes start=@ end=@ after=@ ~]
=/ start=id-post:c
?^ tim=(slaw %da start.pole) u.tim
(slav %ud start.pole)
=/ end=id-post:c
?^ tim=(slaw %da end.pole) u.tim
(slav %ud end.pole)
=/ after=id-post:c
?^ tim=(slaw %da after.pole) u.tim
(slav %ud after.pole)
=; posts=v-posts:c
=/ newer
?~ newer=(tab:on-v-posts:c posts.channel `end 1)
~
`key:(head newer)
=/ older
?~ older=(bat:mo-v-posts:c posts.channel `start 1)
~
`key:(head older)
?: ?=(%v2 version)
=/ =paged-posts:c
[(uv-posts-2:utils posts) `before older (wyt:on-v-posts:c posts)]
[(uv-posts-2:utils posts) newer older (wyt:on-v-posts:c posts)]
``channel-posts-2+!>(paged-posts)
=/ =paged-posts:v1:old:c
[(uv-posts:utils posts) `before older (wyt:on-v-posts:c posts)]
[(uv-posts:utils posts) newer older (wyt:on-v-posts:c posts)]
``channel-posts+!>(paged-posts)
:: walk both posts and logs, in chronological order, newest-first,
:: until we accumulate the desired amount of results
::
::NOTE would manually walk the tree, but logic gets rather confusing,
:: so we just eat the conversion overhead here
=/ posts (bap:on-v-posts:c (lot:on-v-posts:c posts.channel ~ `before))
=/ logs (bap:log-on:c (lot:log-on:c log.channel ~ `before))
=| s=[=_limit older=_`(unit time)`(some before) out=v-posts:c]
=< [older out]
|- ^+ s
?: =(0 limit.s) s
?~ posts
:: cannot have logs if posts already empty ::REVIEW right?
::
s(older ~)
=* pit key.i.posts
=/ lit ?~(logs pit key.i.logs)
?: (gte pit lit)
:: post is newer than logs
::
=? s !(has:on-v-posts:c out.s pit)
[(dec limit.s) `pit (put:on-v-posts:c out.s i.posts)]
$(posts t.posts)
:: log is newer than posts
::
?> ?=(^ logs)
?. ?=(%post -.val.i.logs) $(logs t.logs)
=* id id.val.i.logs
=? s !(has:on-v-posts:c out.s id)
:+ (dec limit.s) `lit
(put:on-v-posts:c out.s id (got:on-v-posts:c posts.channel id))
$(logs t.logs)
=/ posts (lot:on-v-posts:c posts.channel `(sub start 1) `(add end 1))
=/ updated (tap:updated-on:c (lot:updated-on:c last-updated.channel `after ~))
%- (log |.("posts: {<(lent posts)>}"))
%- (log |.("updated: {<(lent updated)>}"))
%- (log |.("start: {<start>}"))
%- (log |.("end: {<end>}"))
=| out=v-posts:c
|- ^+ out
:: no posts in this range
?~ posts ~
:: no changes after this point
?~ updated out
=* changed val.i.updated
%- (log |.("changed post: {<changed>}"))
%- (log |.(" gte start: {<(gte changed start)>}"))
%- (log |.(" lte end: {<(lte changed end)>}"))
:: if the post is not in our subset, skip
?~ post=(get:on-v-posts:c posts changed)
$(updated t.updated)
=. out (put:on-v-posts:c out changed u.post)
$(updated t.updated)
::
[%post time=@ ~]
=/ time (slav %ud time.pole)
Expand Down
18 changes: 18 additions & 0 deletions desk/sur/channels.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@
=window
=future
pending=pending-messages
=last-updated
==
--
+$ last-updated ((mop time id-post) lte)
++ updated-on ((on time id-post) lte)
:: $v-post: a channel post
::
+$ v-post [v-seal (rev essay)]
Expand Down Expand Up @@ -526,6 +529,21 @@
++ on-simple-replies ((on id-reply simple-reply) lte)
++ old
|%
++ v6
|%
++ v-channels (map nest v-channel)
++ v-channel
|^ ,[global:^v-channel local]
+$ local
$: =net
=log
=remark
=window:^v-channel
=future:^v-channel
pending=pending-messages
==
--
--
++ v1
|%
+$ post [seal [rev=@ud essay]]
Expand Down

0 comments on commit d3ffe77

Please sign in to comment.