mirror of
https://github.com/logseq/logseq.git
synced 2026-05-03 02:16:30 +00:00
Simple query performance enhancements (#12262)
* perf: separate scalar from ref property query * fix: query bindings * perf: separate default value query from others * fix: import properties first and then other datoms
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
[logseq.db.common.sqlite :as common-sqlite]
|
||||
[logseq.db.common.view :as db-view]
|
||||
[logseq.db.frontend.class :as db-class]
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
[logseq.db.sqlite.create-graph :as sqlite-create-graph]
|
||||
[logseq.db.sqlite.export :as sqlite-export]
|
||||
[logseq.db.sqlite.gc :as sqlite-gc]
|
||||
@@ -244,8 +245,19 @@
|
||||
conn (common-sqlite/get-storage-conn storage schema)
|
||||
_ (db-fix/check-and-fix-schema! repo conn)
|
||||
_ (when datoms
|
||||
(let [data (map (fn [datom]
|
||||
[:db/add (:e datom) (:a datom) (:v datom)]) datoms)]
|
||||
(let [eid->datoms (group-by :e datoms)
|
||||
{properties true non-properties false} (group-by
|
||||
(fn [[_eid datoms]]
|
||||
(boolean
|
||||
(some (fn [datom] (and (= (:a datom) :db/ident)
|
||||
(db-property/property? (:v datom))))
|
||||
datoms)))
|
||||
eid->datoms)
|
||||
datoms (concat (mapcat second properties)
|
||||
(mapcat second non-properties))
|
||||
data (map (fn [datom]
|
||||
[:db/add (:e datom) (:a datom) (:v datom)])
|
||||
datoms)]
|
||||
(d/transact! conn data {:initial-db? true})))
|
||||
client-ops-conn (when-not @*publishing? (common-sqlite/get-storage-conn
|
||||
client-ops-storage
|
||||
@@ -387,7 +399,9 @@
|
||||
(def-thread-api :thread-api/q
|
||||
[repo inputs]
|
||||
(when-let [conn (worker-state/get-datascript-conn repo)]
|
||||
(apply d/q (first inputs) @conn (rest inputs))))
|
||||
(worker-util/profile
|
||||
(str "Datalog query: " inputs)
|
||||
(apply d/q (first inputs) @conn (rest inputs)))))
|
||||
|
||||
(def-thread-api :thread-api/datoms
|
||||
[repo & args]
|
||||
|
||||
Reference in New Issue
Block a user