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:
Tienson Qin
2025-12-19 19:37:51 +08:00
committed by GitHub
parent 045cd5f537
commit aea9f09fd1
5 changed files with 271 additions and 156 deletions

View File

@@ -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]