Skip to content

Instantly share code, notes, and snippets.

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 favila/a93662a47952c5eda6708a1e5fddd791 to your computer and use it in GitHub Desktop.
Save favila/a93662a47952c5eda6708a1e5fddd791 to your computer and use it in GitHub Desktop.
;; same thing using reduction over d/datoms.
;; Objective is to avoid realizing too much in memory
;; May still be slow, but won't OOM
(defn orgs->max-fks [db]
(reduce (fn [o->fk [content-eid _ content-fk]]
(let [org-id (-> (d/entity db content-eid)
:content/collection
:collection/organization
:db/id)]
;; We know content-fk is always increasing,
;; so we just write over the previous seen
(assoc o->fk org-id content-fk)))
{}
;; You can skip over some of these with d/index-range if you know a
;; higher fk that all orgs have at least one fk above
(d/datoms db :avet :content/fk)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment