Forked from jdkealy/gist:75451acf435a877df198abe4a028042c
Last active
February 3, 2017 17:29
-
-
Save favila/a93662a47952c5eda6708a1e5fddd791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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