mirror of https://github.com/logseq/logseq
fix: compute block/refs and block/path-refs after pulling remote
parent
707ba7004f
commit
86b70c1f6d
|
@ -3,10 +3,21 @@
|
|||
(:require [clojure.string :as string]
|
||||
[logseq.common.util.page-ref :as page-ref]
|
||||
[datascript.core :as d]
|
||||
[logseq.db.sqlite.util :as sqlite-util]))
|
||||
[logseq.db.sqlite.util :as sqlite-util]
|
||||
[logseq.common.util :as common-util]))
|
||||
|
||||
(defonce page-ref-special-chars "~^")
|
||||
|
||||
(defonce special-id-ref-pattern
|
||||
(re-pattern
|
||||
(str
|
||||
"(?i)"
|
||||
"\\[\\[~\\^"
|
||||
"("
|
||||
common-util/uuid-pattern
|
||||
")"
|
||||
"\\]\\]")))
|
||||
|
||||
(defn special-id->page
|
||||
"Convert special id backs to page name."
|
||||
[content refs]
|
||||
|
|
|
@ -19,13 +19,15 @@
|
|||
(lookup-entity e :block/content default-value)
|
||||
|
||||
(= k :block/content)
|
||||
(let [result (lookup-entity e k default-value)
|
||||
refs (:block/refs e)
|
||||
tags (:block/tags e)]
|
||||
(or
|
||||
(when (string? result)
|
||||
(db-content/special-id->page result (distinct (concat refs tags))))
|
||||
default-value))
|
||||
(or
|
||||
(get (.-kv e) k)
|
||||
(let [result (lookup-entity e k default-value)
|
||||
refs (:block/refs e)
|
||||
tags (:block/tags e)]
|
||||
(or
|
||||
(when (string? result)
|
||||
(db-content/special-id->page result (distinct (concat refs tags))))
|
||||
default-value)))
|
||||
|
||||
:else
|
||||
(or (get (.-kv e) k)
|
||||
|
|
|
@ -208,7 +208,7 @@
|
|||
(reset! (:editor/create-page? @state/state) false))))
|
||||
|
||||
(defn ^:api rebuild-block-refs
|
||||
[repo conn date-formatter block new-properties & {:keys [skip-content-parsing?]}]
|
||||
[repo conn date-formatter block new-properties]
|
||||
(let [db @conn
|
||||
property-key-refs (keys new-properties)
|
||||
property-value-refs (->> (vals new-properties)
|
||||
|
@ -236,16 +236,14 @@
|
|||
property-refs (->> (concat property-key-refs property-value-refs)
|
||||
(map (fn [id-or-map] (if (uuid? id-or-map) {:block/uuid id-or-map} id-or-map)))
|
||||
(remove (fn [b] (nil? (d/entity db [:block/uuid (:block/uuid b)])))))
|
||||
content-refs (when-not skip-content-parsing?
|
||||
(when-let [content (:block/content block)]
|
||||
(gp-block/extract-refs-from-text repo db content date-formatter)))]
|
||||
content-refs (when-let [content (:block/content block)]
|
||||
(gp-block/extract-refs-from-text repo db content date-formatter))]
|
||||
(concat property-refs content-refs)))
|
||||
|
||||
(defn- rebuild-refs
|
||||
[repo conn date-formatter txs-state block m]
|
||||
(when (sqlite-util/db-based-graph? repo)
|
||||
(let [refs (->> (rebuild-block-refs repo conn date-formatter block (:block/properties block)
|
||||
:skip-content-parsing? true)
|
||||
(let [refs (->> (rebuild-block-refs repo conn date-formatter block (:block/properties block))
|
||||
(concat (:block/refs m))
|
||||
(concat (if (seq (:block/tags m))
|
||||
(:block/tags m)
|
||||
|
|
|
@ -70,10 +70,10 @@
|
|||
:default)))
|
||||
|
||||
(defn- rebuild-block-refs
|
||||
[repo block new-properties & opts]
|
||||
[repo block new-properties]
|
||||
(let [conn (db/get-db repo false)
|
||||
date-formatter (state/get-date-formatter)]
|
||||
(outliner-core/rebuild-block-refs repo conn date-formatter block new-properties opts)))
|
||||
(outliner-core/rebuild-block-refs repo conn date-formatter block new-properties)))
|
||||
|
||||
(defn convert-property-input-string
|
||||
[schema-type v-str]
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
[cljs-time.core :as t]
|
||||
[cljs.core.async :as async :refer [<! >! chan go go-loop]]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as string]
|
||||
[cognitect.transit :as transit]
|
||||
[frontend.worker.async-util :include-macros true :refer [<?]]
|
||||
[logseq.outliner.core :as outliner-core]
|
||||
|
@ -27,7 +28,9 @@
|
|||
[frontend.worker.rtc.ws :as ws]
|
||||
[frontend.worker.rtc.asset-sync :as asset-sync]
|
||||
[promesa.core :as p]
|
||||
[cljs-bean.core :as bean]))
|
||||
[cljs-bean.core :as bean]
|
||||
[logseq.db.frontend.content :as db-content]
|
||||
[logseq.common.util.page-ref :as page-ref]))
|
||||
|
||||
;; +-------------+
|
||||
;; | |
|
||||
|
@ -97,6 +100,7 @@
|
|||
(defmethod transact-db! :delete-blocks [_ & args]
|
||||
(outliner-tx/transact!
|
||||
{:persist-op? false
|
||||
:outliner-op :delete-blocks
|
||||
:transact-opts {:repo (first args)
|
||||
:conn (second args)}}
|
||||
(apply outliner-core/delete-blocks! args)))
|
||||
|
@ -104,6 +108,7 @@
|
|||
(defmethod transact-db! :move-blocks [_ & args]
|
||||
(outliner-tx/transact!
|
||||
{:persist-op? false
|
||||
:outliner-op :move-blocks
|
||||
:transact-opts {:repo (first args)
|
||||
:conn (second args)}}
|
||||
(apply outliner-core/move-blocks! args)))
|
||||
|
@ -111,6 +116,7 @@
|
|||
(defmethod transact-db! :insert-blocks [_ & args]
|
||||
(outliner-tx/transact!
|
||||
{:persist-op? false
|
||||
:outliner-op :insert-blocks
|
||||
:transact-opts {:repo (first args)
|
||||
:conn (second args)}}
|
||||
(apply outliner-core/insert-blocks! args)))
|
||||
|
@ -118,6 +124,7 @@
|
|||
(defmethod transact-db! :save-block [_ & args]
|
||||
(outliner-tx/transact!
|
||||
{:persist-op? false
|
||||
:outliner-op :save-block
|
||||
:transact-opts {:repo (first args)
|
||||
:conn (second args)}}
|
||||
(apply outliner-core/save-block! args)))
|
||||
|
@ -269,6 +276,20 @@
|
|||
(assert (some? shape) properties*)
|
||||
(transact-db! :upsert-whiteboard-block conn [(gp-whiteboard/shape->block repo db shape page-name)])))))
|
||||
|
||||
(defn- special-id-ref->page
|
||||
"Convert special id ref backs to page name."
|
||||
[db content]
|
||||
(let [matches (distinct (re-seq db-content/special-id-ref-pattern content))]
|
||||
(if (seq matches)
|
||||
(reduce (fn [content [full-text id]]
|
||||
(if-let [page (d/entity db [:block/uuid (uuid id)])]
|
||||
(string/replace content full-text
|
||||
(str page-ref/left-brackets
|
||||
(:block/original-name page)
|
||||
page-ref/right-brackets))
|
||||
content)) content matches)
|
||||
content)))
|
||||
|
||||
(defn- update-block-attrs
|
||||
[repo conn date-formatter block-uuid {:keys [parents properties _content] :as op-value}]
|
||||
(let [key-set (set/intersection
|
||||
|
@ -289,7 +310,8 @@
|
|||
(cond-> b-ent
|
||||
(and (contains? key-set :content)
|
||||
(not= (:content op-value)
|
||||
(:block/raw-content b-ent))) (assoc :block/content (:content op-value))
|
||||
(:block/raw-content b-ent))) (assoc :block/content
|
||||
(special-id-ref->page @conn (:content op-value)))
|
||||
(contains? key-set :updated-at) (assoc :block/updated-at (:updated-at op-value))
|
||||
(contains? key-set :created-at) (assoc :block/created-at (:created-at op-value))
|
||||
(contains? key-set :alias) (assoc :block/alias (some->> (seq (:alias op-value))
|
||||
|
|
Loading…
Reference in New Issue