Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhead in pull-attr-datoms #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 38 additions & 38 deletions src/datascript/pull_api.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[transient-coll items]
(reduce conj! transient-coll items))

(def ^:private ^:const +default-limit+ 1000)
;; (defonce ^:private ^:const +default-limit+ 1000)

(defn- initial-frame
[pattern eids multi?]
Expand Down Expand Up @@ -108,45 +108,45 @@

(defn- pull-attr-datoms
[db attr-key attr eid forward? datoms opts [parent & frames]]
(let [limit (get opts :limit +default-limit+)
found (not-empty
(cond->> datoms
limit (into [] (take limit))))]
(if found
(let [ref? (db/ref? db attr)
component? (and ref? (db/component? db attr))
multi? (if forward? (db/multival? db attr) (not component?))
datom-val (if forward? (fn [^Datom d] (.-v d)) (fn [^Datom d] (.-e d)))]
(cond
(contains? opts :subpattern)
(->> (subpattern-frame (:subpattern opts)
(mapv datom-val found)
multi? attr-key)
(conj frames parent))
(if-let [found (not-empty
(if-let [limit (get opts :limit)]
(take limit datoms)
datoms))]
(let [ref? (db/ref? db attr)
component? (and ref? (db/component? db attr))
multi? (if forward? (db/multival? db attr) (not component?))
datom-val (if forward? (fn [^Datom d] (.-v d)) (fn [^Datom d] (.-e d)))]
(cond
(contains? opts :subpattern)
(->> (subpattern-frame (:subpattern opts)
(mapv datom-val found)
multi? attr-key)
(conj frames parent))

(contains? opts :recursion)
(recurse-attr db attr-key multi?
(mapv datom-val found)
eid parent frames)
(contains? opts :recursion)
(recurse-attr db attr-key multi?
(mapv datom-val found)
eid parent frames)

(and component? forward?)
(->> found
(mapv datom-val)
(expand-frame parent eid attr-key multi?)
(conj frames parent))

:else
(let [as-value (cond->> datom-val
ref? (comp #(hash-map :db/id %)))
single? (not multi?)]
(->> (cond-> (into [] (map as-value) found)
single? first)
(update parent :kvps assoc! attr-key)
(conj frames)))))
(->> (cond-> parent
(contains? opts :default)
(update :kvps assoc! attr-key (:default opts)))
(conj frames)))))
(and component? forward?)
(->> found
(mapv datom-val)
(expand-frame parent eid attr-key multi?)
(conj frames parent))
:else
(let [as-value (if ref?
(comp (partial hash-map :db/id) datom-val)
datom-val)]
(->>
(if-not multi?
(as-value (first found))
(map as-value found))
(update parent :kvps assoc! attr-key)
(conj frames)))))
(->> (cond-> parent
(contains? opts :default)
(update :kvps assoc! attr-key (:default opts)))
(conj frames))))

(defn- pull-attr
[db spec eid frames]
Expand Down