mirror of https://github.com/logseq/logseq
Move entity plus to db dep
parent
d593456c1c
commit
38ba0dfa7c
|
@ -13,7 +13,8 @@
|
|||
[logseq.common.config :as common-config]
|
||||
[logseq.db.frontend.content :as db-content]
|
||||
[clojure.set :as set]
|
||||
[logseq.db.frontend.rules :as rules]))
|
||||
[logseq.db.frontend.rules :as rules]
|
||||
[logseq.db.frontend.entity-plus]))
|
||||
|
||||
;; Use it as an input argument for datalog queries
|
||||
(def block-attrs
|
||||
|
@ -501,3 +502,9 @@
|
|||
(d/pull-many db
|
||||
'[:db/id :block/name :block/original-name]
|
||||
ids)))))
|
||||
|
||||
(comment
|
||||
(defn db-based-graph?
|
||||
"Whether the current graph is db-only"
|
||||
[db]
|
||||
(= "db" (:db/type (d/entity db :db/type)))))
|
||||
|
|
|
@ -1,26 +1,24 @@
|
|||
(ns frontend.db.datascript.entity-plus
|
||||
(ns logseq.db.frontend.entity-plus
|
||||
"Add map ops such as assoc/dissoc to datascript Entity"
|
||||
(:require [cljs.core]
|
||||
[datascript.impl.entity :as entity :refer [Entity]]
|
||||
[frontend.state :as state]
|
||||
[frontend.config :as config]
|
||||
[frontend.db.utils :as db-utils]))
|
||||
[logseq.db.frontend.content :as db-content]))
|
||||
|
||||
(def lookup-entity @#'entity/lookup-entity)
|
||||
(defn lookup-kv-then-entity
|
||||
([e k] (lookup-kv-then-entity e k nil))
|
||||
([^Entity e k default-value]
|
||||
(cond
|
||||
(and (= k :block/raw-content) (config/db-based-graph? (state/get-current-repo)))
|
||||
(= k :block/raw-content)
|
||||
(lookup-entity e :block/content default-value)
|
||||
|
||||
(and (= k :block/content) (config/db-based-graph? (state/get-current-repo)))
|
||||
(= k :block/content)
|
||||
(let [result (lookup-entity e k default-value)
|
||||
refs (:block/refs e)
|
||||
tags (:block/tags e)]
|
||||
(or
|
||||
(when (string? result)
|
||||
(db-utils/special-id->page result (distinct (concat refs tags))))
|
||||
(db-content/special-id->page result (distinct (concat refs tags))))
|
||||
default-value))
|
||||
|
||||
:else
|
|
@ -69,8 +69,8 @@
|
|||
retracted-blocks)]
|
||||
(when (and (seq retracted-tx') (fn? set-state-fn))
|
||||
(set-state-fn [:editor/last-replace-ref-content-tx repo]
|
||||
{:retracted-block-ids retracted-block-ids
|
||||
:revert-tx revert-tx}))
|
||||
{:retracted-block-ids retracted-block-ids
|
||||
:revert-tx revert-tx}))
|
||||
(concat txs retracted-tx' macros-tx))
|
||||
txs))
|
||||
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
If no transactions are included in `body`, it does not save a transaction.
|
||||
`Args`:
|
||||
`opts`: Every key is optional, opts except `additional-tx` will be transacted as `tx-meta`.
|
||||
{:graph \"Which graph will be transacted to\"
|
||||
:outliner-op \"For example, :save-block, :insert-blocks, etc. \"
|
||||
{:outliner-op \"For example, :save-block, :insert-blocks, etc. \"
|
||||
:additional-tx \"Additional tx data that can be bundled together
|
||||
with the body in this macro.\"
|
||||
:persist-op? \"Boolean, store ops into db (sqlite), by default,
|
||||
|
@ -37,10 +36,8 @@
|
|||
(when transaction-opts#
|
||||
(conj! transaction-opts# opts#))
|
||||
~@body)
|
||||
(let [repo# (get-in opts# [:transact-opts :repo])
|
||||
transaction-args# (cond-> {:repo repo#}
|
||||
(and (logseq.db.sqlite.util/db-based-graph? repo#)
|
||||
(get opts*# :persist-op? true))
|
||||
(let [transaction-args# (cond-> {}
|
||||
(get opts*# :persist-op? true)
|
||||
(assoc :persist-op? true))]
|
||||
(binding [logseq.outliner.core/*transaction-data* (transient [])
|
||||
logseq.outliner.core/*transaction-opts* (transient [])
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
[logseq.common.util :as common-util]
|
||||
[cljs-time.core :as t]
|
||||
[cljs-time.format :as tf]
|
||||
;; add map ops to datascript Entity
|
||||
[frontend.db.datascript.entity-plus :as entity-plus]
|
||||
[frontend.config :as config]
|
||||
[logseq.db :as ldb]))
|
||||
|
||||
|
|
|
@ -260,9 +260,3 @@
|
|||
(js/console.error error)))))
|
||||
(recur))
|
||||
chan))
|
||||
|
||||
(comment
|
||||
(defn db-graph?
|
||||
"Whether the current graph is db-only"
|
||||
[]
|
||||
(= "db" (:db/type (db-utils/entity :db/type)))))
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
[datascript.transit :as dt]
|
||||
[frontend.db.conn :as conn]
|
||||
[frontend.config :as config]
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.db.frontend.content :as db-content]))
|
||||
|
||||
;; transit serialization
|
||||
|
|
|
@ -65,6 +65,9 @@
|
|||
[:map {:closed true}
|
||||
[:*graph-uuid :any]
|
||||
[:*repo :any]
|
||||
[:*db-conn :any]
|
||||
[:*token :any]
|
||||
[:*date-formatter :any]
|
||||
[:data-from-ws-chan :any]
|
||||
[:data-from-ws-pub :any]
|
||||
[:*stop-rtc-loop-chan :any]
|
||||
|
@ -73,6 +76,7 @@
|
|||
[:toggle-auto-push-client-ops-chan :any]
|
||||
[:*auto-push-client-ops? :any]
|
||||
[:force-push-client-ops-chan :any]])
|
||||
|
||||
(def state-validator
|
||||
(let [validator (m/validator state-schema)]
|
||||
(fn [data]
|
||||
|
@ -91,22 +95,30 @@
|
|||
|
||||
(defmethod transact-db! :delete-blocks [_ & args]
|
||||
(outliner-tx/transact!
|
||||
{:persist-op? false}
|
||||
{:persist-op? false
|
||||
:transact-opts {:repo (first args)
|
||||
:conn (second args)}}
|
||||
(apply outliner-core/delete-blocks! args)))
|
||||
|
||||
(defmethod transact-db! :move-blocks [_ & args]
|
||||
(outliner-tx/transact!
|
||||
{:persist-op? false}
|
||||
{:persist-op? false
|
||||
:transact-opts {:repo (first args)
|
||||
:conn (second args)}}
|
||||
(apply outliner-core/move-blocks! args)))
|
||||
|
||||
(defmethod transact-db! :insert-blocks [_ & args]
|
||||
(outliner-tx/transact!
|
||||
{:persist-op? false}
|
||||
{:persist-op? false
|
||||
:transact-opts {:repo (first args)
|
||||
:conn (second args)}}
|
||||
(apply outliner-core/insert-blocks! args)))
|
||||
|
||||
(defmethod transact-db! :save-block [_ & args]
|
||||
(outliner-tx/transact!
|
||||
{:persist-op? false}
|
||||
{:persist-op? false
|
||||
:transact-opts {:repo (first args)
|
||||
:conn (second args)}}
|
||||
(apply outliner-core/save-block! args)))
|
||||
|
||||
(defmethod transact-db! :delete-whiteboard-blocks [_ conn block-uuids]
|
||||
|
@ -272,7 +284,7 @@
|
|||
:else
|
||||
(let [b-ent (d/entity @conn [:block/uuid block-uuid])
|
||||
new-block
|
||||
(cond-> (d/entity @conn (:db/id b-ent))
|
||||
(cond-> b-ent
|
||||
(and (contains? key-set :content)
|
||||
(not= (:content op-value)
|
||||
(:block/content b-ent))) (assoc :block/content (:content op-value))
|
||||
|
@ -294,7 +306,7 @@
|
|||
|
||||
(defn apply-remote-move-ops
|
||||
[repo conn date-formatter sorted-move-ops]
|
||||
(prn :sorted-move-ops sorted-move-ops)
|
||||
(prn :repo repo :sorted-move-ops sorted-move-ops)
|
||||
(doseq [{:keys [parents left self] :as op-value} sorted-move-ops]
|
||||
(let [r (check-block-pos @conn self parents left)]
|
||||
(case r
|
||||
|
@ -678,13 +690,13 @@
|
|||
|
||||
|
||||
(defn- <client-op-update-handler
|
||||
[state token]
|
||||
[state _token]
|
||||
{:pre [(some? @(:*graph-uuid state))
|
||||
(some? @(:*repo state))]}
|
||||
(go
|
||||
(let [repo @(:*repo state)
|
||||
conn @(:*db-conn state)
|
||||
date-formatter (:*date-formatter state)]
|
||||
date-formatter @(:*date-formatter state)]
|
||||
(op-mem-layer/new-branch! repo)
|
||||
(try
|
||||
(let [ops-for-remote (sort-remote-ops (gen-block-uuid->remote-ops repo conn))
|
||||
|
@ -884,7 +896,7 @@
|
|||
(defn <start-rtc
|
||||
[repo conn token]
|
||||
(go
|
||||
(let [state (<init-state repo token)
|
||||
(let [state (<! (<init-state repo token))
|
||||
config (worker-state/get-config repo)]
|
||||
(if-let [graph-uuid (op-mem-layer/get-graph-uuid repo)]
|
||||
(<! (<loop-for-rtc state graph-uuid repo conn (common-config/get-date-formatter config)))
|
||||
|
|
Loading…
Reference in New Issue