Browse Source

fix: db unlisten

Tienson Qin 5 days ago
parent
commit
d2cdcf91d1
1 changed files with 5 additions and 3 deletions
  1. 5 3
      deps/db/src/logseq/db.cljs

+ 5 - 3
deps/db/src/logseq/db.cljs

@@ -248,7 +248,7 @@
   (let [db-before @conn
         *tx-data (atom [])]
     (try
-      (when (:batch-tx @conn)
+      (when (:batch-tx? @conn)
         (throw (ex-info "batch-transact! can't be nested called" {:tx-meta tx-meta})))
       (d/listen! conn ::batch-tx
                  (fn [tx-report]
@@ -276,9 +276,11 @@
       (catch :default e
         (log/error e)
         (reset! conn db-before)
+        (throw e))
+      (finally
+        (d/unlisten! conn ::batch-tx)
         (swap! conn dissoc :skip-store? :batch-tx?)
-        (reset! *tx-data nil)
-        (throw e)))))
+        (reset! *tx-data nil)))))
 
 (def page? entity-util/page?)
 (def internal-page? entity-util/internal-page?)