This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-29
Channels
- # announcements (1)
- # biff (5)
- # calva (10)
- # cljdoc (4)
- # clojure (17)
- # clojure-europe (15)
- # clojure-norway (38)
- # clojurescript (53)
- # community-development (1)
- # cursive (2)
- # datomic (14)
- # fulcro (11)
- # funcool (1)
- # hyperfiddle (7)
- # introduce-yourself (2)
- # jobs-discuss (17)
- # missionary (7)
- # releases (4)
- # shadow-cljs (30)
- # slack-help (6)
- # specter (5)
- # squint (22)
I believe I've read that it's a best practice to batch transactions (though can't immediately find refence to it and maybe it's "unofficial" advice), eg calling (partition-all 1000 ...)
and calling d/transact
on those batches.
Is the same true of using d/with
, and if so, how do you accumulate a result? is it possible to get a new with-db
from the result of with
? Or since it's just an in memory thing it's fine to just transact huge amounts of datoms?
let's say STATS
here is a sequence of maps that each have 6 double attributes.
;; this wont work, the db here will just be the result of transacting the last batch only
(let [conn (d/with-db conn1)
db (:db-after
(reduce
(fn [_ batch]
(d/with conn {:tx-data batch}))
conn
(partition-all 1000 STATS)))]
(d/q
'[:find (count ?e)
:where [?e ::stat]]
db))
> is it possible to get a new with-db
from the result of with
?
it returns the same as d/transact, so it includes :db-after
, which will be a with-db (unless this is broken in cloud--it definitely works on on-prem)
(let [conn (d/with-db conn1)
db (reduce
(fn [conn batch]
(:db-after (d/with conn {:tx-data batch})))
conn
(partition-all 100 STATS))]
(d/q
'[:find (count ?e)
:where [?e ::stat]]
db))
Ah you're right this does work, thanks(let [with-db (d/with-db conn1)
db (:db-after
(reduce
(fn [with-db batch]
(:db-after (d/with with-db {:tx-data batch})))
with-db
(partition-all 1000 STATS)))]
(d/q
'[:find (count ?e)
:where [?e ::stat]]
db))
you have to manually accumulate the subsequent dbs instead of relying on d/transact side-effects
you can simulate what d/transact and a connection is doing by keeping an atom with the latest with-db in it and calling it “conn”.
On on-prem there’s even a library for this: https://github.com/vvvvalvalval/datomock