Skip to content

Instantly share code, notes, and snippets.

@stuarthalloway
Created August 5, 2015 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuarthalloway/c216188a17bb0f09701c to your computer and use it in GitHub Desktop.
Save stuarthalloway/c216188a17bb0f09701c to your computer and use it in GitHub Desktop.
Information about Datomic log ts
;; This program walks the entire log extracting information about t
;; Does not reveal any domain data.
;; Scans entire log, so run against a backup instead of production if possible!
(require '[datomic.api :as d]
'[clojure.pprint :as pp])
(defn max-t
"Returns the maximum t mentioned in a collection of datoms"
[datoms]
(reduce
(fn [n datom]
(max n (d/tx->t (:e datom)) (d/tx->t (:tx datom))))
0
datoms))
(defn log-ts*
[conn n]
(let [log (d/log conn)]
(->> (d/tx-range log n nil)
(partition 2 1)
(map (fn [[tx1 tx2]]
{:t1 (:t tx1)
:t1-next (max-t (:data tx1))
:t2 (:t tx2)})))))
(defn log-ts
[uri n]
(let [conn (d/connect uri)]
(binding [*print-length* nil]
(pp/pprint
(log-ts* conn n)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment