-
Notifications
You must be signed in to change notification settings - Fork 17
/
composites.clj
26 lines (24 loc) · 1.1 KB
/
composites.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
;; Copyright (c) Cognitect, Inc. All rights reserved.
(ns datomic.dodc.composites
(:require [datomic.client.api :as d]))
(defn establish-composite
"Reasserts all values of attr, in batches of batch-size, with
pacing-sec pause between transactions. This will establish values
for any composite attributes built from attr."
[conn {:keys [attr batch-size pacing-sec]}]
(let [db (d/db conn)
es (d/datoms db {:index :aevt
:components [attr]
:limit -1})]
(doseq [batch (partition-all batch-size es)]
(let [es (into #{} (map :e batch))
result (d/transact conn {:tx-data (map (fn [{:keys [e v]}]
[:db/add e attr v])
batch)})
added (transduce
(comp (map :e) (filter es))
(completing (fn [x ids] (inc x)))
0
(:tx-data result))]
(println {:batch-size batch-size :first-e (:e (first batch)) :added added})
(Thread/sleep (* 1000 pacing-sec))))))