ソースを参照

fix: parser large var

Gabriel Horner 1 年間 前
コミット
f41ce9d6df
1 ファイル変更41 行追加36 行削除
  1. 41 36
      deps/graph-parser/src/logseq/graph_parser/block.cljs

+ 41 - 36
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -395,6 +395,42 @@
        (text/namespace-page? page)
        (not (common-date/valid-journal-title-with-slash? page))))
 
+(defn- ref->map
+  [db *col {:keys [date-formatter db-based? *name->id tag?]}]
+  (let [col (remove string/blank? @*col)
+        children-pages (when-not db-based?
+                         (->> (mapcat (fn [p]
+                                        (let [p (if (map? p)
+                                                  (:block/title p)
+                                                  p)]
+                                          (when (string? p)
+                                            (let [p (or (text/get-nested-page-name p) p)]
+                                              (when (text/namespace-page? p)
+                                                (common-util/split-namespace-pages p))))))
+                                      col)
+                              (remove string/blank?)
+                              (distinct)))
+        col (->> (distinct (concat col children-pages))
+                 (remove nil?))]
+    (map
+     (fn [item]
+       (let [macro? (and (map? item)
+                         (= "macro" (:type item)))]
+         (when-not macro?
+           (let [m (page-name->map item db true date-formatter {:class? tag?})
+                 result (cond->> m
+                          (and db-based? tag? (not (:db/ident m)))
+                          (db-class/build-new-class db))
+                 page-name (if db-based? (:block/title result) (:block/name result))
+                 id (get @*name->id page-name)]
+             (when (nil? id)
+               (swap! *name->id assoc page-name (:block/uuid result)))
+             ;; Changing a :block/uuid should be done cautiously here as it can break
+             ;; the identity of built-in concepts in db graphs
+             (if id
+               (assoc result :block/uuid id)
+               result))))) col)))
+
 (defn- with-page-refs-and-tags
   [{:keys [title body tags refs marker priority] :as block} db date-formatter parse-block]
   (let [db-based? (ldb/db-based-graph? db)
@@ -424,41 +460,10 @@
      (concat title body))
     (swap! *refs #(remove string/blank? %))
     (let [*name->id (atom {})
-          ref->map-fn (fn [*col tag?]
-                        (let [col (remove string/blank? @*col)
-                              children-pages (when-not db-based?
-                                               (->> (mapcat (fn [p]
-                                                              (let [p (if (map? p)
-                                                                        (:block/title p)
-                                                                        p)]
-                                                                (when (string? p)
-                                                                  (let [p (or (text/get-nested-page-name p) p)]
-                                                                    (when (text/namespace-page? p)
-                                                                      (common-util/split-namespace-pages p))))))
-                                                            col)
-                                                    (remove string/blank?)
-                                                    (distinct)))
-                              col (->> (distinct (concat col children-pages))
-                                       (remove nil?))]
-                          (map
-                           (fn [item]
-                             (let [macro? (and (map? item)
-                                               (= "macro" (:type item)))]
-                               (when-not macro?
-                                 (let [m (page-name->map item db true date-formatter {:class? tag?})
-                                       result (cond->> m
-                                                (and db-based? tag? (not (:db/ident m)))
-                                                (db-class/build-new-class db))
-                                       page-name (if db-based? (:block/title result) (:block/name result))
-                                       id (get @*name->id page-name)]
-                                   (when (nil? id)
-                                     (swap! *name->id assoc page-name (:block/uuid result)))
-                                   ;; Changing a :block/uuid should be done cautiously here as it can break
-                                   ;; the identity of built-in concepts in db graphs
-                                   (if id
-                                     (assoc result :block/uuid id)
-                                     result))))) col)))
-          refs (->> (ref->map-fn *refs false)
+          ref->map-options {:db-based? db-based?
+                            :date-formatter date-formatter
+                            :*name->id *name->id}
+          refs (->> (ref->map db *refs ref->map-options)
                     (remove nil?)
                     (map (fn [ref]
                            (let [ref' (if-let [entity (ldb/get-case-page db (:block/title ref))]
@@ -469,7 +474,7 @@
                              (cond-> ref'
                                (:block.temp/original-page-name ref)
                                (assoc :block.temp/original-page-name (:block.temp/original-page-name ref)))))))
-          tags (ref->map-fn *structured-tags true)]
+          tags (ref->map db *structured-tags (assoc ref->map-options :tag? true))]
       (assoc block
              :refs refs
              :tags tags))))