Просмотр исходного кода

fix: creating redundant pages when editing a block

Tienson Qin 1 год назад
Родитель
Сommit
210be5aaca

+ 1 - 48
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -452,53 +452,6 @@
           with-block-refs
           (update :refs (fn [col] (remove nil? col)))))
 
-(defn- with-path-refs
-  [blocks]
-  (loop [blocks blocks
-         acc []
-         parents []]
-    (if (empty? blocks)
-      acc
-      (let [block (first blocks)
-            cur-level (:block/level block)
-            level-diff (- cur-level
-                          (get (last parents) :block/level 0))
-            [path-refs parents]
-            (cond
-              (zero? level-diff)            ; sibling
-              (let [path-refs (mapcat :block/refs (drop-last parents))
-                    parents (conj (vec (butlast parents)) block)]
-                [path-refs parents])
-
-              (> level-diff 0)              ; child
-              (let [path-refs (mapcat :block/refs parents)]
-                [path-refs (conj parents block)])
-
-              (< level-diff 0)              ; new parent
-              (let [parents (vec (take-while (fn [p] (< (:block/level p) cur-level)) parents))
-                    path-refs (mapcat :block/refs parents)]
-                [path-refs (conj parents block)]))
-            path-ref-pages (->> path-refs
-                                (concat (:block/refs block))
-                                (map (fn [ref]
-                                       (cond
-                                         (map? ref)
-                                         (:block/name ref)
-
-                                         :else
-                                         ref)))
-                                (remove string/blank?)
-                                (map (fn [ref]
-                                       (if (string? ref)
-                                         {:block/name (common-util/page-name-sanity-lc ref)}
-                                         ref)))
-                                (remove vector?)
-                                (remove nil?)
-                                (distinct))]
-        (recur (rest blocks)
-               (conj acc (assoc block :block/path-refs path-ref-pages))
-               parents)))))
-
 (defn- macro->block
   "macro: {:name \"\" arguments [\"\"]}"
   [macro]
@@ -562,7 +515,7 @@
                    (select-keys first-block [:block/format :block/page]))
                   blocks)
                  blocks)]
-    (with-path-refs blocks)))
+    blocks))
 
 (defn- with-heading-property
   [properties markdown-heading? size]

+ 2 - 6
deps/graph-parser/src/logseq/graph_parser/extract.cljc

@@ -234,18 +234,14 @@
           blocks (map (fn [block]
                         (if (contains? (:block/type block) "macro")
                           block
-                          (let [block-ref-pages (seq (:block/refs block))
-                                page-lookup-ref [:block/name page-name]
-                                block-path-ref-pages (->> (cons page-lookup-ref (seq (:block/path-refs block)))
-                                                          (remove nil?))]
+                          (let [block-ref-pages (seq (:block/refs block))]
                             (when block-ref-pages
                               (swap! ref-pages set/union (set block-ref-pages)))
                             (-> block
                                 (dissoc :ref-pages)
                                 (assoc :block/format format
                                        :block/page [:block/name page-name]
-                                       :block/refs block-ref-pages
-                                       :block/path-refs block-path-ref-pages)))))
+                                       :block/refs block-ref-pages)))))
                       blocks)
           [properties invalid-properties properties-text-values]
           (if (:block/pre-block? (first blocks))

+ 9 - 2
deps/outliner/src/logseq/outliner/core.cljs

@@ -267,7 +267,15 @@
                         (fn [t]
                           {:db/id (ref->eid t)
                            :block/type "class"})
-                        (:block/tags m))]
+                        (:block/tags m))
+          refs (map (fn [ref]
+                      (if (and (map? ref)
+                               (:block/name ref))
+                        (let [page-id (:db/id (ldb/get-page @conn (:block/name ref)))]
+                          (cond-> ref
+                            (some? page-id)
+                            (assoc :db/id page-id)))
+                        ref)) refs)]
       (swap! txs-state (fn [txs] (concat txs [{:db/id (:db/id block)
                                                :block/refs refs}]
                                          add-tag-type))))))
@@ -395,7 +403,6 @@
                                       (concat (keep :db/id (:block/tags block-entity))
                                               (keep ref->eid tags))))
               m)]
-
       ;; Ensure block UUID never changes
       (let [e (d/entity db db-id)]
         (when (and e block-uuid)

+ 1 - 1
src/main/frontend/worker/pipeline.cljs

@@ -77,7 +77,7 @@
   (when-not (:pipeline-replace? (:tx-meta tx-report))
     (let [tx-meta (:tx-meta tx-report)
           {:keys [from-disk? new-graph? undo? redo?]} tx-meta]
-      (if (or from-disk? new-graph?)
+      (if (or from-disk? new-graph?)    ; FIXME: compute block path refs
         {:tx-report tx-report}
         (let [{:keys [pages blocks]} (ds-report/get-blocks-and-pages tx-report)
               _ (when (sqlite-util/local-file-based-graph? repo)