1
0
Эх сурвалжийг харах

enhance(dev): importing cli debug option prints all tx

related to a failing path. Helpfully provides more context
and also doesn't misleadingly print tx when it's not related to an
import failure with another path
Gabriel Horner 9 сар өмнө
parent
commit
6c58af2605

+ 16 - 6
deps/graph-parser/script/db_import.cljs

@@ -6,7 +6,6 @@
             ["fs/promises" :as fsp]
             ["os" :as os]
             ["path" :as node-path]
-            #_:clj-kondo/ignore
             [babashka.cli :as cli]
             [cljs.pprint :as pprint]
             [clojure.set :as set]
@@ -14,15 +13,22 @@
             [datascript.core :as d]
             [logseq.common.graph :as common-graph]
             [logseq.graph-parser.exporter :as gp-exporter]
+            #_:clj-kondo/ignore
             [logseq.outliner.cli :as outliner-cli]
+            [logseq.outliner.pipeline :as outliner-pipeline]
             [nbb.classpath :as cp]
             [nbb.core :as nbb]
             [promesa.core :as p]))
 
-(def last-tx-data (atom nil))
+(def tx-queue (atom cljs.core/PersistentQueue.EMPTY))
 (def original-transact! d/transact!)
 (defn dev-transact! [conn tx-data tx-meta]
-  (reset! last-tx-data tx-data)
+  (swap! tx-queue (fn [queue]
+                        (let [new-queue (conj queue {:tx-data tx-data :tx-meta tx-meta})]
+                          ;; Only care about last few so vary 10 as needed
+                          (if (> (count new-queue) 10)
+                            (pop new-queue)
+                            new-queue))))
   (original-transact! conn tx-data tx-meta))
 
 (defn- build-graph-files
@@ -54,7 +60,7 @@
     (println "Ex-data:" (pr-str (merge (dissoc (:ex-data m) :error)
                                        (when-let [err (get-in m [:ex-data :error])]
                                          {:original-error (ex-data (.-cause err))}))))
-    (println "Stacktrace:")
+    (println "\nStacktrace:")
     (if-let [stack (some-> (get-in m [:ex-data :error]) ex-data :sci.impl/callstack deref)]
       (println (string/join
                 "\n"
@@ -66,8 +72,12 @@
                  (reverse stack))))
       (println (some-> (get-in m [:ex-data :error]) .-stack)))
     (when debug
-      (println "Last Tx Data:")
-      (pprint/pprint @last-tx-data)))
+      (when-let [matching-tx (seq (filter #(and (get-in m [:ex-data :path])
+                                                (or (= (get-in % [:tx-meta ::gp-exporter/path]) (get-in m [:ex-data :path]))
+                                                    (= (get-in % [:tx-meta ::outliner-pipeline/original-tx-meta ::gp-exporter/path]) (get-in m [:ex-data :path]))))
+                                          @tx-queue))]
+        (println (str "\n" (count matching-tx)) "Tx Maps for failing path:")
+        (pprint/pprint matching-tx))))
   (when (and (= :error (:level m)) (not continue))
     (js/process.exit 1)))
 

+ 3 - 3
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -1349,7 +1349,7 @@
         (split-pages-and-properties-tx pages-tx old-properties existing-pages (:import-state options))
         ;; _ (when (seq property-pages-tx) (cljs.pprint/pprint {:property-pages-tx property-pages-tx}))
         ;; Necessary to transact new property entities first so that block+page properties can be transacted next
-        main-props-tx-report (d/transact! conn property-pages-tx {::new-graph? true})
+        main-props-tx-report (d/transact! conn property-pages-tx {::new-graph? true ::path file})
 
         classes-tx @(:classes-tx tx-options)
         {:keys [retract-page-tags-tx] pages-tx'' :pages-tx} (clean-extra-invalid-tags @conn pages-tx' classes-tx existing-pages)
@@ -1374,12 +1374,12 @@
         ;;                        [:whiteboard-pages :pages-index :page-properties-tx :property-page-properties-tx :pages-tx' :classes-tx :blocks-index :blocks-tx]
         ;;                        [whiteboard-pages pages-index page-properties-tx property-page-properties-tx pages-tx' classes-tx blocks-index blocks-tx]))
         ;; _ (when (not (seq whiteboard-pages)) (cljs.pprint/pprint {#_:property-pages-tx #_property-pages-tx :pages-tx pages-tx :tx tx'}))
-        main-tx-report (d/transact! conn tx' {::new-graph? true})
+        main-tx-report (d/transact! conn tx' {::new-graph? true ::path file})
 
         upstream-properties-tx
         (build-upstream-properties-tx @conn @(:upstream-properties tx-options) (:import-state options) log-fn)
         ;; _ (when (seq upstream-properties-tx) (cljs.pprint/pprint {:upstream-properties-tx upstream-properties-tx}))
-        upstream-tx-report (when (seq upstream-properties-tx) (d/transact! conn upstream-properties-tx {::new-graph? true}))]
+        upstream-tx-report (when (seq upstream-properties-tx) (d/transact! conn upstream-properties-tx {::new-graph? true ::path file}))]
 
     ;; Return all tx-reports that occurred in this fn as UI needs to know what changed
     [main-props-tx-report main-tx-report upstream-tx-report]))

+ 2 - 1
deps/outliner/src/logseq/outliner/pipeline.cljs

@@ -221,7 +221,8 @@
   [conn tx-report]
   (let [{:keys [blocks]} (ds-report/get-blocks-and-pages tx-report)
         refs-tx-report (when-let [refs-tx (and (seq blocks) (rebuild-block-refs-tx tx-report blocks))]
-                         (ldb/transact! conn refs-tx {:pipeline-replace? true}))
+                         (ldb/transact! conn refs-tx {:pipeline-replace? true
+                                                      ::original-tx-meta (:tx-meta tx-report)}))
         blocks' (if refs-tx-report
                   (keep (fn [b] (d/entity (:db-after refs-tx-report) (:db/id b))) blocks)
                   blocks)