eyre: simplify channel subscription storage

Instead of storing by "channel wire", store by request-id instead.
The channel wire was just the channel-id, request-id, and some cruft.
This commit is contained in:
fang 2020-10-19 00:48:18 +02:00
parent 69d70b98a2
commit 63b4fb3e19
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972
4 changed files with 29 additions and 18 deletions

View File

@ -385,9 +385,9 @@
:- 'subscriptions'
:- %a
%+ turn ~(tap by subscriptions)
|= [=wire [=^ship app=term =^path *]]
|= [id=@ud [=^ship app=term =^path *]]
%- pairs
:~ 'wire'^(^path wire)
:~ 'id'^(numb id)
'ship'^(^ship ship)
'app'^s+app
'path'^(^path path)

View File

@ -1353,8 +1353,6 @@
%subscribe
::
=, i.requests
=/ channel-wire=wire
(channel-wire channel-id request-id)
::
=. gall-moves
:_ gall-moves
@ -1368,24 +1366,26 @@
=. session.channel-state.state
%+ ~(jab by session.channel-state.state) channel-id
|= =channel
channel(subscriptions (~(put by subscriptions.channel) channel-wire [ship app path duct]))
=- channel(subscriptions -)
%+ ~(put by subscriptions.channel)
request-id
[ship app path duct]
::
$(requests t.requests)
::
%unsubscribe
=/ channel-wire=wire
(channel-wire channel-id subscription-id.i.requests)
=, i.requests
::
=/ usession (~(get by session.channel-state.state) channel-id)
?~ usession
$(requests t.requests)
=/ subscriptions subscriptions:u.usession
::
?~ maybe-subscription=(~(get by subscriptions) channel-wire)
?~ maybe-subscription=(~(get by subscriptions) subscription-id)
:: the client sent us a weird request referring to a subscription
:: which isn't active.
::
~& [%missing-subscription-in-unsubscribe channel-wire]
~& [%missing-subscription-in-unsubscribe channel-id subscription-id]
$(requests t.requests)
::
=. gall-moves
@ -1401,7 +1401,9 @@
=. session.channel-state.state
%+ ~(jab by session.channel-state.state) channel-id
|= =channel
channel(subscriptions (~(del by subscriptions.channel) channel-wire))
=- channel(subscriptions -)
%- ~(del by subscriptions.channel)
subscription-id
::
$(requests t.requests)
::
@ -1646,10 +1648,10 @@
:: produce a list of moves which cancels every gall subscription
::
%+ turn ~(tap by subscriptions.session)
|= [channel-wire=wire ship=@p app=term =path duc=^duct]
|= [request-id=@ud ship=@p app=term =path duc=^duct]
^- move
:^ duc %pass
(weld channel-wire /(scot %p ship)/[app])
(subscription-wire channel-id request-id ship app)
[%g %deal [our ship] app %leave ~]
--
:: +handle-gall-error: a call to +poke-http-response resulted in a %coup
@ -2448,8 +2450,17 @@
:: than wiping channels entirely.
session.channel-state.server-state.old
%- ~(run by session.channel-state.server-state.old)
|= =channel-2020-9-30
channel-2020-9-30(events *(qeu [@ud @ud channel-event]))
|= old-channel=channel-2020-9-30
^- channel
%= old-channel
events *(qeu [@ud @ud channel-event])
::
subscriptions
%- ~(gas by *(map @ud [@p term path duct]))
%+ turn ~(tap by subscriptions.old-channel)
|= [=wire rest=[@p term path duct]]
[(slav %ud (snag 3 wire)) rest]
==
==
::
%~2020.5.29

View File

@ -1401,12 +1401,12 @@
:: can't assume it got received until we get an acknowledgment.
::
events=(qeu [id=@ud request-id=@ud =channel-event])
:: subscriptions: gall subscriptions
:: subscriptions: gall subscriptions by request-id
::
:: We maintain a list of subscriptions so if a channel times out, we
:: can cancel all the subscriptions we've made.
::
subscriptions=(map wire [ship=@p app=term =path duc=duct])
subscriptions=(map @ud [ship=@p app=term =path duc=duct])
:: heartbeat: sse heartbeat timer
::
heartbeat=(unit timer)

View File

@ -117,10 +117,10 @@ export class Eyre extends Component {
</>);
const subscriptionItems = c.subscriptions.map(s => {
//NOTE jsx sorta copied from /components/subscriptions
return {key: `${s.wire} ${s.app} ${s.ship} ${s.path}`, jsx: (
return {key: `${s.id} ${s.app} ${s.ship} ${s.path}`, jsx: (
<div class="flex">
<div class="flex-auto" style={{maxWidth: '35%'}}>
{s.wire}
{s.id}
</div>
<div class="flex-auto" style={{maxWidth: '15%'}}>
~{s.ship}