datahike

https://datahike.io/, Join the conversation at https://discord.com/invite/kEBzMvb, history for this channel is available at https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/datahike
sova-soars-the-sora 2020-06-23T00:15:29.410100Z

Hi is it possible to do joins in one query?

sova-soars-the-sora 2020-06-23T00:16:16.411Z

For example, i'd like to get the results from 2 different transactions, together. one tx has :msg/id :msg/content :msg/authorid the other tx has :user/displayname :user/authorid

whilo 2020-06-23T04:06:53.412300Z

@sova If you know how these two transactions related, i.e. how to join them, you can just use a logical variable for that. Maybe I misunderstand what you exactly mean, feel free to elaborate a bit on the data you are transacting.

sova-soars-the-sora 2020-06-23T19:43:33.412600Z

So I have this very costly query

sova-soars-the-sora 2020-06-23T19:44:24.413100Z

Well, the query is fast, but the map is slow, because I run 3 functions inside it, and I'd like to upgrade them to query-level once I figure out all the data I need precisely

sova-soars-the-sora 2020-06-23T19:44:28.413400Z

(defn get-latest-chats [] 
   (->>
      (d/q '[:find ?authorid ?content ?messageid ?timestamp
			       :in $ ?kind 
			       :where
			       [?m :message/kind      ?kind]
			       [?m :message/messageid ?messageid]
			       [?m :message/content   ?content]
			       [?m :message/authorid  ?authorid]
			       [?m :message/timestamp ?timestamp]]
			  					@conn "chat")
      (map (fn [[ aid content mid ts ]]
         { :authorid aid :messageid mid :content content :timestamp ts :displayname (get-display-name aid)  :votes-up (get-vote-count-ups mid) :votes-down (get-vote-count-downs mid)}))
      (into [])
      (sort-by :timestamp)
      (take 3)))

sova-soars-the-sora 2020-06-23T19:45:02.414100Z

Top part gets a message, map portion puts nice keys on the data in the order it got from the result, and i also add three keys there

sova-soars-the-sora 2020-06-23T19:45:23.414600Z

but I only (take 3) so can I do those 3 functions after the take

sova-soars-the-sora 2020-06-23T19:45:34.414800Z

i think that will speed it up significantly

sova-soars-the-sora 2020-06-23T20:31:56.415100Z

got it working ^.^

🎉 2