pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
souenzzo 2021-02-09T00:23:47.202100Z

@henrik I work on an pathom app for 1+years now. Now I'm facing some issues because I let my db value at env We are moving the db into input

wilkerlucio 2021-02-09T01:26:05.202300Z

you could also keep db as something mutable in env (as an atom) and update it anytime you see fit (for sync process this should be fine, for parallel not so much)

wilkerlucio 2021-02-09T01:26:31.202500Z

@souenzzo one thing to be careful about db as input is to be sure you are not leaking it out

wilkerlucio 2021-02-09T01:26:48.202700Z

(or allowing the users to request teh full db on their queries)

wilkerlucio 2021-02-09T01:28:14.202900Z

in Pathom 3 that's quite easy (and efficient) to do, using wrap-map-select-entry, in Pathom 2 its doable, but needs to walk the output to be sure (still easy, but not efficient)

πŸŽ‰ 1
imre 2021-02-09T12:39:02.205500Z

Hey folks. Given a pathom2 system where I currently have the following resolvers:

{::pc/input #{::aaa/input}
 ::pc/output [::aaa/output]}
and
{::pc/input #{::bbb/input}
 ::pc/output [::bbb/output]}
I want to create a wrapper layer over them that would receive ::api/input and return ::api/output, routing the request to one of the above based on some condition in the input. I have the initial resolver roughly as:
{::pc/input #{::api/input}
 ::pc/output [::aaa/input ::bbb/input]}
(if (use-aaa? input)
  {::aaa/input {}}
  {::bbb/input {}})
But I'm having trouble coercing ::aaa/output or ::bbb/output to ::api/output. How would I go about this? There exist mappings for both aaa->api-output and bbb->api-output.
{::pc/input ???
 ::pc/output [::api/output]}

fjolne 2021-02-10T17:19:39.221200Z

@imre JFYI there’s also async-parser, which allows to return core.async channels and has lower overhead than parallel-parser IIRC

imre 2021-02-10T17:20:01.221400Z

Thank you, I'm actually experimenting with that πŸ™‚

imre 2021-02-11T14:38:18.226Z

Thanks you for your help so far. Mind if I ask what is the recommended reader to be used with async-parser? (and parallel-parser for that matter) I've just been getting into pathom lately

imre 2021-02-11T14:57:59.226200Z

Let me rephrase a bit: if I use the async-parser, should is my best choice of reader the async-reader2?

wilkerlucio 2021-02-11T18:55:07.229200Z

yes, async-reader2 with async parser

1
wilkerlucio 2021-02-09T13:25:47.205700Z

hello, I think you can make it work with some aliases, just keep the two resolvers you mentioned first, and add:

[(pc/alias-resolver ::api/input ::aaa/input)
 (pc/alias-resolver ::api/input ::bbb/input)
 (pc/alias-resolver ::aaa/output ::api/output)
 (pc/alias-resolver ::bbb/output ::api/output)]

imre 2021-02-09T13:33:27.206100Z

Aren't aliases for the case when the 2 sides of it look the same? In my case there have to be mappings.

imre 2021-02-09T13:35:15.206300Z

It works fine when I only have the ::aaa/output -> ::api/output resolver but when I add the ::bbb/output -> ::api/output one I'm no longer getting the aaa case resolved

imre 2021-02-09T13:35:30.206500Z

It might be something with how my parser is set up

wilkerlucio 2021-02-09T13:39:58.206700Z

ah, you right

wilkerlucio 2021-02-09T13:40:07.206900Z

for the input you should do a routing like you mentioned

wilkerlucio 2021-02-09T13:40:11.207100Z

and for output you can use alias

wilkerlucio 2021-02-09T13:43:16.207300Z

complete example:

wilkerlucio 2021-02-09T13:43:18.207500Z

; A adds 10
(pc/defresolver a-output [{:keys [a/input]}]
  {:a/output (+ input 10)})

; B multiplies by 2
(pc/defresolver b-output [{:keys [b/input]}]
  {:b/output (* input 2)})

; lets give evens to A, odds to B
(pc/defresolver input-selector [{:keys [api/input]}]
  {::pc/output [:a/input :b/input]}
  (if (even? input)
    {:a/input input}
    {:b/input input}))

(def register
  [a-output
   b-output
   input-selector
   (pc/alias-resolver :a/output :api/output)
   (pc/alias-resolver :b/output :api/output)])

(def parser
  (p/parser
    {::p/env     {::p/reader               [p/map-reader
                                            pc/reader2
                                            pc/open-ident-reader
                                            p/env-placeholder-reader]
                  ::p/placeholder-prefixes #{">"}}
     ::p/mutate  pc/mutate
     ::p/plugins [(pc/connect-plugin {::pc/register register})
                  p/error-handler-plugin
                  p/request-cache-plugin
                  p/trace-plugin]}))

(comment
  (parser {} [{[:api/input 16] [:api/output]}]) ; => 26
  (parser {} [{[:api/input 17] [:api/output]}]) ; => 34
  )

imre 2021-02-09T13:50:03.207900Z

Thank you kindly. It is certainly something with my parser setup then, as the above example does not work with it but it does in your code

imre 2021-02-09T13:53:45.208400Z

Thank you. Cannot access your second link there, perhaps you sent me the wrong one

fjolne 2021-02-09T13:55:23.208600Z

ah, sorry, right https://nextjournal.com/a/9KJX2jnmNJBppKKFXHu3mb

imre 2021-02-09T13:56:11.208800Z

Thank you very much.

imre 2021-02-09T13:57:06.209Z

Running my resolvers with these parsers works, so I'll need to dig into that. We're using the parallel parser but I haven't familiarized myself with its configuration yet, but it seems the problem lies there somewhere.

fjolne 2021-02-09T14:02:50.209200Z

i've had some weird problems with parallel parser, which made me to switch to a regular one; those were hardly reproducible though so I doubt that's it for one thing you can check whether you have pc/open-ident-reader included

imre 2021-02-09T14:04:36.209400Z

::p/reader [p/map-reader
             pc/reader3
             pc/open-join-context-reader
             pc/open-ident-reader
             p/env-placeholder-reader]

imre 2021-02-09T14:04:49.209600Z

looks like I do

fjolne 2021-02-09T14:07:27.209800Z

ah, reader3 is experimental, it doesn't work as expected in this case

imre 2021-02-09T14:08:58.210Z

Well, drat. I'll need to look into why we started using it then πŸ˜„

wilkerlucio 2021-02-09T15:35:49.210200Z

@imre parallel parser has its quirks, and maybe its a bug related to that, in the reality of Pathom 2 parallel parser is that the overhead it adds is just too high for most applications

wilkerlucio 2021-02-09T15:36:19.210400Z

unless you have a really big amount of parallelizable things (and are willing to pay some premium on the servers), its usually more efficient (in speed and cost) to stay with reader2

wilkerlucio 2021-02-09T15:36:54.210600Z

and about reader3, yeah, that's was an experiment and it is outdate in Pathom 2 (it was the bases for Pathom 3, but in Pathom 3 it evolved a lot since)

imre 2021-02-09T15:42:18.210900Z

Thank you. I'll check back in the history why we use reader3 but it being outdated is a definite warning sign.

imre 2021-02-09T15:43:56.211100Z

WRT parallel, what do you mean by really big amount? In this current case I'm working on there are some library calls that take a significant amount of time and we would prefer to parallelize calls to them.

wilkerlucio 2021-02-09T16:45:18.212200Z

I suggest you do a few comparisons and check the final time

wilkerlucio 2021-02-09T16:45:44.213Z

if they are close, stick to serial, since its also easier to debug

imre 2021-02-09T17:06:41.213200Z

Thank you