From 640bb138137c6d3f6fe0d2597563f5e15927cdc1 Mon Sep 17 00:00:00 2001 From: Tenari Date: Tue, 10 Oct 2023 17:09:08 -0500 Subject: [PATCH 1/2] some thread-based testing utilities --- realm/lib/passport.hoon | 3 +- realm/ted/make-fake-contacts.hoon | 48 +++++++++++++++++++++++++++++++ realm/ted/send-all-contacts.hoon | 21 ++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 realm/ted/make-fake-contacts.hoon create mode 100644 realm/ted/send-all-contacts.hoon diff --git a/realm/lib/passport.hoon b/realm/lib/passport.hoon index 24f7da3..daa3cf5 100644 --- a/realm/lib/passport.hoon +++ b/realm/lib/passport.hoon @@ -258,13 +258,14 @@ |= [contacts=(list [t=@da =contact:common]) state=state-0 =bowl:gall] ^- (quip card state-0) ?< =(src.bowl our.bowl) :: assert we aren't receiving from ourself - =/ log1 (maybe-log hide-logs.state "%receive-contacts: {}") + =/ log1 (maybe-log hide-logs.state "%receive-contacts: {<(lent contacts)>} contacts {}") :: loop through the contacts they sent us =/ old=(list [id:common @da contact:common]) (our-contacts:scries bowl) =/ cards=(list card) ~ |- ?: =(0 (lent contacts)) + =/ log2 (maybe-log hide-logs.state "%receive-contacts finished at {} ") [cards state] =/ con=contact:common (cleanup-contact contact:(snag 0 contacts)) ?: =(our.bowl ship.con) :: don't create a contact record for ourselves diff --git a/realm/ted/make-fake-contacts.hoon b/realm/ted/make-fake-contacts.hoon new file mode 100644 index 0000000..f24e2ef --- /dev/null +++ b/realm/ted/make-fake-contacts.hoon @@ -0,0 +1,48 @@ +:: -realm!make-fake-contacts 10 +/- spider, common +/+ *strandio + +|^ +=, strand=strand:spider +^- thread:spider +|= arg=vase +=/ m (strand ,vase) +^- form:m +=/ axn=(unit @ud) !<((unit @ud) arg) +?~ axn (strand-fail %no-arg ~) +;< our=@p bind:m get-our +;< now=@da bind:m get-time +=/ i=@ud 1 +|- + ?: =(u.axn i) + (pure:m !>(`@p`i)) + =/ cont=contact:common + [ + `@p`i + [~ [%nft nft='https://steamavatar.io/img/1477787732RP7QJ.jpg']] + [~ '#B17BD7'] + [~ 'Just another test moon'] + [~ 'Paul'] + ] + ;< ~ bind:m (poke [our %bedrock] db-action+!>([%create [our (add now i)] /private contact-type:common [%contact cont] ~])) + $(i +(i)) +:: +++ take-fact-or-kick + |= =wire + =/ m (strand ,(unit cage)) + ^- form:m + |= tin=strand-input:strand + ?+ in.tin `[%skip ~] + ~ `[%wait ~] + :: + [~ %agent * %fact *] + ?. =(watch+wire wire.u.in.tin) + `[%skip ~] + `[%done (some cage.sign.u.in.tin)] + :: + [~ %agent * %kick *] + ?. =(watch+wire wire.u.in.tin) + `[%skip ~] + `[%done ~] + == +-- diff --git a/realm/ted/send-all-contacts.hoon b/realm/ted/send-all-contacts.hoon new file mode 100644 index 0000000..b6f5ea3 --- /dev/null +++ b/realm/ted/send-all-contacts.hoon @@ -0,0 +1,21 @@ +:: -realm!send-all-contacts ~bus +/- spider +/+ *strandio, passport + +|^ +=, strand=strand:spider +^- thread:spider +|= arg=vase +=/ m (strand ,vase) +^- form:m +=/ axn=(unit @p) !<((unit @p) arg) +?~ axn (strand-fail %no-arg ~) +;< our=@p bind:m get-our +;< now=@da bind:m get-time +=/ bol=bowl:gall *bowl:gall +=. our.bol our +=. now.bol now +~& >>> "starting send-all-contacts {}" +;< ~ bind:m (poke [u.axn %passport] passport-action+!>([%receive-contacts (current-contacts:passport bol)])) +(pure:m !>('sent')) +-- From 1356cb9c942d8e0e742efc846d5c9a843f05acbe Mon Sep 17 00:00:00 2001 From: Tenari Date: Tue, 10 Oct 2023 17:44:56 -0500 Subject: [PATCH 2/2] use create-many for faster contact-sharing --- realm/lib/passport.hoon | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/realm/lib/passport.hoon b/realm/lib/passport.hoon index daa3cf5..7c67629 100644 --- a/realm/lib/passport.hoon +++ b/realm/lib/passport.hoon @@ -122,6 +122,10 @@ |= [our=ship =type:common data=columns:db] (create-req our type data [our *@da]) :: +++ create-many + |= [our=ship args=(list [req-id input-row:db])] + [%pass /dbpoke %agent [our %bedrock] %poke %db-action !>([%create-many args])] +:: ++ edit-req |= [our=ship =type:common =id:common data=columns:db =req-id] ^- card @@ -263,23 +267,31 @@ :: loop through the contacts they sent us =/ old=(list [id:common @da contact:common]) (our-contacts:scries bowl) =/ cards=(list card) ~ + =/ create-args=(list [req-id input-row:db]) ~ |- ?: =(0 (lent contacts)) =/ log2 (maybe-log hide-logs.state "%receive-contacts finished at {} ") - [cards state] + ?: =(0 (lent create-args)) + [cards state] + ~& > "lent of create-args {<(lent create-args)>}" + ~& > "lent of cards {<(lent cards)>}" + :_ state + :- (create-many our.bowl create-args) + cards =/ con=contact:common (cleanup-contact contact:(snag 0 contacts)) ?: =(our.bowl ship.con) :: don't create a contact record for ourselves $(contacts +.contacts) =/ index=(unit @) (find-contact con old) - =/ new-card=(unit card) - ?~ index - (some (create our.bowl contact-type:common [%contact con])) - =/ old-con=[=id:common t=@da =contact:common] (snag u.index old) - ?: (gth t.old-con t:(snag 0 contacts)) ~ :: if our old record is newer than the one we are getting, ignore it - (some (edit our.bowl contact-type:common id.old-con [%contact con])) + ?~ index + %= $ + contacts +.contacts + create-args [[[our.bowl *@da] [/private contact-type:common [%contact con] ~]] create-args] + == + =/ old-con=[=id:common t=@da =contact:common] (snag u.index old) + ?: (gth t.old-con t:(snag 0 contacts)) $(contacts +.contacts) :: if our old record is newer than the one we are getting, ignore it %= $ contacts +.contacts - cards ?~(new-card cards [u.new-card cards]) + cards [(edit our.bowl contact-type:common id.old-con [%contact con]) cards] == :: ++ request-contacts