Quellcode durchsuchen

fix: compute block/refs and block/path-refs after pulling remote

Tienson Qin vor 1 Jahr
Ursprung
Commit
86b70c1f6d

+ 12 - 1
deps/db/src/logseq/db/frontend/content.cljs

@@ -3,10 +3,21 @@
   (:require [clojure.string :as string]
   (:require [clojure.string :as string]
             [logseq.common.util.page-ref :as page-ref]
             [logseq.common.util.page-ref :as page-ref]
             [datascript.core :as d]
             [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 page-ref-special-chars "~^")
 
 
+(defonce special-id-ref-pattern
+  (re-pattern
+   (str
+    "(?i)"
+    "\\[\\[~\\^"
+    "("
+    common-util/uuid-pattern
+    ")"
+    "\\]\\]")))
+
 (defn special-id->page
 (defn special-id->page
   "Convert special id backs to page name."
   "Convert special id backs to page name."
   [content refs]
   [content refs]

+ 9 - 7
deps/db/src/logseq/db/frontend/entity_plus.cljc

@@ -19,13 +19,15 @@
      (lookup-entity e :block/content default-value)
      (lookup-entity e :block/content default-value)
 
 
      (= k :block/content)
      (= 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
      :else
      (or (get (.-kv e) k)
      (or (get (.-kv e) k)

+ 4 - 6
deps/outliner/src/logseq/outliner/core.cljs

@@ -208,7 +208,7 @@
      (reset! (:editor/create-page? @state/state) false))))
      (reset! (:editor/create-page? @state/state) false))))
 
 
 (defn ^:api rebuild-block-refs
 (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
   (let [db @conn
         property-key-refs (keys new-properties)
         property-key-refs (keys new-properties)
         property-value-refs (->> (vals new-properties)
         property-value-refs (->> (vals new-properties)
@@ -236,16 +236,14 @@
         property-refs (->> (concat property-key-refs property-value-refs)
         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)))
                            (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)])))))
                            (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)))
     (concat property-refs content-refs)))
 
 
 (defn- rebuild-refs
 (defn- rebuild-refs
   [repo conn date-formatter txs-state block m]
   [repo conn date-formatter txs-state block m]
   (when (sqlite-util/db-based-graph? repo)
   (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 (:block/refs m))
                     (concat (if (seq (:block/tags m))
                     (concat (if (seq (:block/tags m))
                               (:block/tags m)
                               (:block/tags m)

+ 2 - 2
src/main/frontend/handler/db_based/property.cljs

@@ -70,10 +70,10 @@
       :default)))
       :default)))
 
 
 (defn- rebuild-block-refs
 (defn- rebuild-block-refs
-  [repo block new-properties & opts]
+  [repo block new-properties]
   (let [conn (db/get-db repo false)
   (let [conn (db/get-db repo false)
         date-formatter (state/get-date-formatter)]
         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
 (defn convert-property-input-string
   [schema-type v-str]
   [schema-type v-str]

+ 24 - 2
src/main/frontend/worker/rtc/core.cljs

@@ -6,6 +6,7 @@
             [cljs-time.core :as t]
             [cljs-time.core :as t]
             [cljs.core.async :as async :refer [<! >! chan go go-loop]]
             [cljs.core.async :as async :refer [<! >! chan go go-loop]]
             [clojure.set :as set]
             [clojure.set :as set]
+            [clojure.string :as string]
             [cognitect.transit :as transit]
             [cognitect.transit :as transit]
             [frontend.worker.async-util :include-macros true :refer [<?]]
             [frontend.worker.async-util :include-macros true :refer [<?]]
             [logseq.outliner.core :as outliner-core]
             [logseq.outliner.core :as outliner-core]
@@ -27,7 +28,9 @@
             [frontend.worker.rtc.ws :as ws]
             [frontend.worker.rtc.ws :as ws]
             [frontend.worker.rtc.asset-sync :as asset-sync]
             [frontend.worker.rtc.asset-sync :as asset-sync]
             [promesa.core :as p]
             [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]
 (defmethod transact-db! :delete-blocks [_ & args]
   (outliner-tx/transact!
   (outliner-tx/transact!
    {:persist-op? false
    {:persist-op? false
+    :outliner-op :delete-blocks
     :transact-opts {:repo (first args)
     :transact-opts {:repo (first args)
                     :conn (second args)}}
                     :conn (second args)}}
    (apply outliner-core/delete-blocks! args)))
    (apply outliner-core/delete-blocks! args)))
@@ -104,6 +108,7 @@
 (defmethod transact-db! :move-blocks [_ & args]
 (defmethod transact-db! :move-blocks [_ & args]
   (outliner-tx/transact!
   (outliner-tx/transact!
    {:persist-op? false
    {:persist-op? false
+    :outliner-op :move-blocks
     :transact-opts {:repo (first args)
     :transact-opts {:repo (first args)
                     :conn (second args)}}
                     :conn (second args)}}
    (apply outliner-core/move-blocks! args)))
    (apply outliner-core/move-blocks! args)))
@@ -111,6 +116,7 @@
 (defmethod transact-db! :insert-blocks [_ & args]
 (defmethod transact-db! :insert-blocks [_ & args]
   (outliner-tx/transact!
   (outliner-tx/transact!
    {:persist-op? false
    {:persist-op? false
+    :outliner-op :insert-blocks
     :transact-opts {:repo (first args)
     :transact-opts {:repo (first args)
                     :conn (second args)}}
                     :conn (second args)}}
    (apply outliner-core/insert-blocks! args)))
    (apply outliner-core/insert-blocks! args)))
@@ -118,6 +124,7 @@
 (defmethod transact-db! :save-block [_ & args]
 (defmethod transact-db! :save-block [_ & args]
   (outliner-tx/transact!
   (outliner-tx/transact!
    {:persist-op? false
    {:persist-op? false
+    :outliner-op :save-block
     :transact-opts {:repo (first args)
     :transact-opts {:repo (first args)
                     :conn (second args)}}
                     :conn (second args)}}
    (apply outliner-core/save-block! args)))
    (apply outliner-core/save-block! args)))
@@ -269,6 +276,20 @@
         (assert (some? shape) properties*)
         (assert (some? shape) properties*)
         (transact-db! :upsert-whiteboard-block conn [(gp-whiteboard/shape->block repo db shape page-name)])))))
         (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
 (defn- update-block-attrs
   [repo conn date-formatter block-uuid {:keys [parents properties _content] :as op-value}]
   [repo conn date-formatter block-uuid {:keys [parents properties _content] :as op-value}]
   (let [key-set (set/intersection
   (let [key-set (set/intersection
@@ -289,7 +310,8 @@
                 (cond-> b-ent
                 (cond-> b-ent
                   (and (contains? key-set :content)
                   (and (contains? key-set :content)
                        (not= (:content op-value)
                        (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 :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 :created-at)     (assoc :block/created-at (:created-at op-value))
                   (contains? key-set :alias)          (assoc :block/alias (some->> (seq (:alias op-value))
                   (contains? key-set :alias)          (assoc :block/alias (some->> (seq (:alias op-value))