Browse Source

fix: store db for debugging too for parent-left conflicts

Tienson Qin 1 year ago
parent
commit
ef8ca41f8c
2 changed files with 12 additions and 9 deletions
  1. 7 4
      src/main/frontend/worker/db/fix.cljs
  2. 5 5
      src/main/frontend/worker/pipeline.cljs

+ 7 - 4
src/main/frontend/worker/db/fix.cljs

@@ -146,11 +146,14 @@
     (filter #(> (count (second %)) 1) parent-left->es)))
 
 (defn- loop-fix-conflicts
-  [conn page-id transact-opts *fix-tx-data from-fix-test?]
+  [conn page-id transact-opts *fix-tx-data tx-report from-fix-test?]
   (let [db @conn
         conflicts (get-conflicts db page-id)
         _ (when (and (not from-fix-test?) (exists? js/process) (seq conflicts))
-            (throw (ex-info "outliner core conflicts" {:conflicts conflicts})))
+            (throw (ex-info "outliner core conflicts" {:conflicts conflicts
+                                                       :db-before (:db-before tx-report)
+                                                       :tx-data (:tx-data tx-report)
+                                                       :tx-meta (:tx-meta tx-report)})))
         fix-conflicts-tx (when (seq conflicts)
                            (fix-parent-left-conflicts db conflicts page-id))]
     (when (seq fix-conflicts-tx)
@@ -159,7 +162,7 @@
       (let [tx-data (:tx-data (ldb/transact! conn fix-conflicts-tx transact-opts))]
         (swap! *fix-tx-data (fn [old-data] (concat old-data tx-data))))
       (when (seq (get-conflicts @conn page-id))
-        (loop-fix-conflicts conn page-id transact-opts *fix-tx-data from-fix-test?)))))
+        (loop-fix-conflicts conn page-id transact-opts *fix-tx-data tx-report from-fix-test?)))))
 
 (defn fix-page-if-broken!
   "Fix the page if it has either parent-left conflicts or broken chains."
@@ -175,7 +178,7 @@
       (let [transact-opts (if replace-tx? {:replace? true} {})
             *fix-tx-data (atom [])]
         (when fix-parent-left?
-          (loop-fix-conflicts conn page-id transact-opts *fix-tx-data from-fix-test?))
+          (loop-fix-conflicts conn page-id transact-opts *fix-tx-data tx-report from-fix-test?))
         (when fix-broken-chain?
           (let [db' @conn
                 parent-left->es' (build-parent-left->es db page-id)

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

@@ -49,7 +49,7 @@
        (remove nil?)))))
 
 (defn fix-db!
-  [conn {:keys [db-before db-after tx-data] :as tx-report}]
+  [conn {:keys [db-before db-after tx-data] :as tx-report} context]
   (let [changed-pages (->> (filter (fn [d] (contains? #{:block/left :block/parent} (:a d))) tx-data)
                            (map :e)
                            distinct
@@ -61,7 +61,8 @@
                            (remove nil?)
                            (distinct))]
     (doseq [changed-page-id changed-pages]
-      (db-fix/fix-page-if-broken! conn changed-page-id {:tx-report tx-report}))))
+      (db-fix/fix-page-if-broken! conn changed-page-id {:tx-report tx-report
+                                                        :context context}))))
 
 (defn validate-and-fix-db!
   [repo conn tx-report context]
@@ -70,9 +71,8 @@
       (when (and (get-in context [:validate-db-options :fail-invalid?]) (not valid?))
         (worker-util/post-message :notification
                                   [["Invalid DB!"] :error]))))
-  (when (or (:dev? context)
-            (exists? js/process))
-    (fix-db! conn tx-report)))
+  (when (or (:dev? context) (exists? js/process))
+    (fix-db! conn tx-report context)))
 
 (defn invoke-hooks
   [repo conn {:keys [db-before db-after] :as tx-report} context]