This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-30
Channels
- # announcements (2)
- # babashka (3)
- # beginners (31)
- # biff (3)
- # calva (40)
- # chlorine-clover (2)
- # clerk (5)
- # clj-kondo (10)
- # clojure (13)
- # clojure-art (1)
- # clojure-denver (16)
- # clojure-europe (44)
- # clojure-nl (1)
- # clojure-norway (27)
- # clojure-sweden (3)
- # clojure-uk (1)
- # clojurescript (49)
- # clr (6)
- # community-development (2)
- # datalevin (10)
- # datomic (63)
- # events (2)
- # fulcro (9)
- # holy-lambda (15)
- # honeysql (8)
- # hoplon (6)
- # hyperfiddle (9)
- # introduce-yourself (1)
- # kaocha (1)
- # london-clojurians (2)
- # matrix (1)
- # nbb (7)
- # off-topic (38)
- # polylith (6)
- # re-frame (4)
- # reagent (2)
- # releases (3)
- # sci (13)
- # scittle (5)
- # shadow-cljs (6)
- # sql (5)
- # tools-deps (4)
- # vim (33)
- # web-security (8)
- # xtdb (2)
Let's say we have a transaction query that is basically increasing a counter to create auto-increment ids for a specific entity. How could I use the resulting tx-data from a transaction of said entity, to retrieve the id used? Is there a straighforward way of doing it?
Can't I use the datoms collection in the tx-data result?
That way I would avoid querying the db once again
ahhaha
true, although, I would need to know the id to get the event 😄
or the entity
if this is a “Create” context, I assume that’s just resolve-tempids, or else you already know some other minted id?
let me show you this
{:db-before {:database-id "iacts-loan-amendments-afe56c56-82a4-4c09-ae56-91c48470b755",
:db-name "iacts-loan-amendments",
:t 2110,
:next-t 2116,
:type :datomic.client/db},
:db-after {:database-id "iacts-loan-amendments-afe56c56-82a4-4c09-ae56-91c48470b755",
:db-name "iacts-loan-amendments",
:t 2116,
:next-t 2122,
:type :datomic.client/db},
:tx-data [#datom[13194139535428 50 #inst"2023-05-30T17:23:34.050-00:00" 13194139535428 true]
#datom[17592186046533 80 "asdasdasda" 13194139535428 true]
#datom[17592186046533 82 1231341234 13194139535428 true]
#datom[17592186046533 79 "this is a comment" 13194139535428 true]
#datom[17592186046533 83 1214134123 13194139535428 true]
#datom[17592186046533 91 17592186046534 13194139535428 true]
#datom[17592186046534 119 17592186045475 13194139535428 true]
#datom[17592186046534 120 17592186046535 13194139535428 true]
#datom[17592186046535 123 0 13194139535428 true]
#datom[17592186046535 124 "this is a a general narrative" 13194139535428 true]
#datom[17592186046533 90 17592186046536 13194139535428 true]
#datom[17592186046536 115 "001" 13194139535428 true]
#datom[17592186046536 116 17592186045428 13194139535428 true]
#datom[17592186046536 117 "this is option 1" 13194139535428 true]
#datom[17592186046533 90 17592186046537 13194139535428 true]
#datom[17592186046537 115 "002" 13194139535428 true]
#datom[17592186046537 116 17592186045428 13194139535428 true]
#datom[17592186046537 117 "this is option 1" 13194139535428 true]
#datom[17592186046533 84 12341234134 13194139535428 true]
#datom[17592186046533 96 "ffrancisco" 13194139535428 true]
#datom[17592186046533 72 "sch" 13194139535428 true]
#datom[17592186046533 78 123123.2 13194139535428 true]
#datom[17592186046533 76 17592186046308 13194139535428 true]
#datom[17592186046533 10 :e17bfada-1933-465e-b3b3-006483f74c34 13194139535428 true]
#datom[17592186046533 81 17592186045438 13194139535428 true]
#datom[17592186046533 95 17592186046221 13194139535428 true]
#datom[17592186046533 73 "sch-ch" 13194139535428 true]
#datom[17592186045418 98 #uuid"e61efbd6-b368-4970-9a5a-e1f38aa2275e" 13194139535428 true]
#datom[17592186045418 98 #uuid"7586e7a4-7182-4476-adee-7f0ff0b47ede" 13194139535428 false]
#datom[17592186045418 99 6 13194139535428 true]
#datom[17592186045418 99 5 13194139535428 false]
#datom[17592186046533 74 5 13194139535428 true]
#datom[17592186046533 75 ["sch" "sch-ch" 5] 13194139535428 true]],
:tempids {"e17bfada-1933-465e-b3b3-006483f74c34" 17592186046533,
"datomic.temp-1000000026938" 17592186046534,
"datomic.temp-1000000026939" 17592186046535,
"datomic.temp-1000000026940" 17592186046536,
"datomic.temp-1000000026941" 17592186046537}}
I am interested in #datom[17592186046533 75 ["sch" "sch-ch" 5] 13194139535428 true]]
the number 5, or the entire vector
how can you use the temp id to resolve the value?
i am sorry, but i am still a noob in these matters 😄
on prem
is there a way to do it with the client api?
yeah, true, I just looked at the code again, I generate the id, so I can just get the eid, and resolve it to a value
there’s no way to avoid the round-trip on client, unless you cache the entity id of the attribute somewhere
well, I can always filter the datom collection and get the value out of the result as well
my problem was matching the eid
to filter the datom collection safely and reliably, you need to know the entity id of the attribute
and with your input, I can now know it for sure, since the temp id, is generated by me in the code
so I just need to use it to get the actual eid, and then filter the datoms to retrieve the value
but if you filter by entity id, most of the datoms in there are assertions on that entity
well, then query it is I guess 😄
attr 75, but the problem is that if the db changes, the attr number will change as well, let's say on a new installation
yeah, I will just resolve the entity and get the correct attribute by name
that way it will actually be correct
(d/pull (:db-after tx-response) [:counter-attr] (get (:tempids tx-response) "e17bfada-1933-465e-b3b3-006483f74c34")
after putting it all together
or generalizing into a query: [:find ?tempid ?realid ?incid :in $ [?tempid …] [[?tempid ?realid]] :where [?realid :counter-attr ?v][(untuple ?v) [_ _ ?incid]]
yeah, I got it, although I like the pull pattern one, looks way more clean 😄
(d/q the-query (:db-after tx-response) ["e17bfada-1933-465e-b3b3-006483f74c34"] (:tempids tx-response))
(defn retrieve-id [temp-id tx-data]
(ffirst (let [eid (get-in tx-data [:tempids temp-id])
db (:db-after tx-data)]
(d/q {:query '[:find ?id
:in $ ?e
:where
[?e :some-entity/some-attr ?id]]
:args [db eid]}))))
thanks for your help, if you're ever in Portugal, I will pay you a beer 😄
whatever you like 🙂
I think that joke didn’t land 🙂 The two sound similar to me in Portuguese so I was always getting them mixed up.
ahhhh well, it depends on the accent maybe
usually people tend to be more familiar with the brazilian accent
so, that might be the reason why it didn't land properly
Brazilians say sorvete, we say gelado
which is worlds different from cerveja 😄
yeah, here it is different, we understand it, but we speak way differently than them
Hello! I am using datomic in prod (first time), we have 4.6G datoms, 2.3M rows of the main entity, 2 transactor instances type i3.large, 2 query instances type t3.xlarge. Currently trying to do a query that pulls almost all the data of a reduced well defined group of entities, let's say the entities that match a certain address. Among the attributes of this entity there's one of cardinality many, and there's 6.7M of them in total. I been doing some performance testing and our api is having trouble handling a ramp of 50 users in 10 secs. I am a bit lost because I don't know if we don't have enough resources or I am doing something wrong myself. Any help or hint would be appreciated.
https://www.youtube.com/watch?v=bvEsnJiCs7E might improve your intuition and give you observability tooling to learn about your performance profile: > Datomic plays a major role in enabling Nubank to scale to over 75 million customers. Across the company, there are more than 3,000 Datomic databases, with over 300 storing more than 10 billion datoms. > > This talk explains Nubank’s use of two features of Datomic to ensure that transactions and queries are as performative as they can be: io-stats, and query-stats. > > The Operating Datomic at Scale talk also aims to show two experiments currently running at Nubank: tuning the memory index to reindex less often, severely reducing expenses with DynamoDB; and the use of ZGC as the garbage collector for JVMs running transactors.
👌 thanks. Will definitely watch it
The speakers are both here in the channel if you have any questions as well. We'd love to offer assistance via <mailto:[email protected]|[email protected]> if you want to dig in further on your specific systems.
Thanks Robert, I am already in touch with support