File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ ; ; Copyright (c) Cognitect, Inc. All rights reserved.
2
+
3
+ (ns datomic.dod.composites
4
+ (:require [datomic.api :as d]))
5
+
6
+ (defn establish-composite
7
+ " Reasserts all values of attr, in batches of batch-size, with
8
+ pacing-sec pause between transactions. This will establish values
9
+ for any composite attributes built from attr."
10
+ [conn {:keys [attr batch-size pacing-sec]}]
11
+ (let [db (d/db conn)
12
+ es (d/datoms db :aevt attr)]
13
+ (doseq [batch (partition-all batch-size es)]
14
+ (let [es (into #{} (map :e batch))
15
+ result @(d/transact conn (map (fn [{:keys [e v]}]
16
+ [:db/add e attr v])
17
+ batch))
18
+ added (transduce
19
+ (comp (map :e ) (filter es))
20
+ (completing (fn [x ids] (inc x)))
21
+ 0
22
+ (:tx-data result))]
23
+ (println {:batch-size batch-size :first-e (:e (first batch)) :added added})
24
+ (Thread/sleep (* 1000 pacing-sec))))))
You can’t perform that action at this time.
0 commit comments