Răsfoiți Sursa

fix: refresh for batch txs

Tienson Qin 1 an în urmă
părinte
comite
696fd4ec0e

+ 6 - 4
src/main/frontend/worker/batch_tx.clj

@@ -1,11 +1,13 @@
 (ns frontend.worker.batch-tx
-  "Macro for batch-tx fns")
+  "Macro for batch-tx fns"
+  (:require [datascript.core :as d]))
 
 (defmacro with-batch-tx-mode
   "1. start batch-tx mode
   2. run body
   3. exit batch-tx mode"
-  [& body]
-  `(do (frontend.worker.batch-tx/start-batch-tx-mode)
+  [conn & body]
+  `(do (d/transact! ~conn [{:db/ident :logseq.kv/tx-batch-mode? :editor/tx-batch-mode? true}])
        ~@body
-       (frontend.worker.batch-tx/exit-batch-tx-mode)))
+       (d/transact! ~conn [{:db/ident :logseq.kv/tx-batch-mode? :editor/tx-batch-mode? false}])
+       (frontend.worker.batch-tx/clear-batch-txs!)))

+ 1 - 14
src/main/frontend/worker/batch_tx.cljs

@@ -5,21 +5,9 @@
             [frontend.schema-register :include-macros true :as sr]))
 
 
-(sr/defkeyword :tx/batch-processing?
-  "will not sync worker-db-changes to UI when true")
-
 (sr/defkeyword :tx/batch-txs
   "store all tx-data when batch-processing")
 
-
-(defn start-batch-tx-mode
-  []
-  (swap! worker-state/*state assoc :tx/batch-processing? true))
-
-(defn tx-batch-processing?
-  []
-  (:tx/batch-processing? @worker-state/*state))
-
 (defn get-batch-txs
   []
   (:tx/batch-txs @worker-state/*state))
@@ -28,7 +16,6 @@
   [tx-data]
   (swap! worker-state/*state update :tx/batch-txs (fn [data] (into data tx-data))))
 
-(defn exit-batch-tx-mode
+(defn clear-batch-txs!
   []
-  (swap! worker-state/*state assoc :tx/batch-processing? false)
   (swap! worker-state/*state assoc :tx/batch-txs nil))

+ 8 - 7
src/main/frontend/worker/pipeline.cljs

@@ -75,7 +75,7 @@
     (fix-db! conn tx-report)))
 
 (defn invoke-hooks
-  [repo conn tx-report context]
+  [repo conn {:keys [db-before db-after] :as tx-report} context]
   (when-not (:pipeline-replace? (:tx-meta tx-report))
     (let [tx-meta (:tx-meta tx-report)
           {:keys [from-disk? new-graph?]} tx-meta]
@@ -114,19 +114,20 @@
                             (d/store @conn)
                             tx-report))
               fix-tx-data (validate-and-fix-db! repo conn tx-report context)
-              batch-processing? (batch-tx/tx-batch-processing?)
-              batch-tx-data (batch-tx/get-batch-txs)
+              before-batch-mode? (:editor/tx-batch-mode? (d/entity db-before :logseq.kv/tx-batch-mode?))
+              now-batch-processing? (:editor/tx-batch-mode? (d/entity db-after :logseq.kv/tx-batch-mode?))
+              exiting-batch-mode? (and before-batch-mode? (not now-batch-processing?))
               full-tx-data (concat (:tx-data tx-report)
                                    fix-tx-data
                                    (:tx-data tx-report')
-                                   (when (and (not batch-processing?) (seq batch-tx-data))
-                                     batch-tx-data))
+                                   (when exiting-batch-mode?
+                                     (batch-tx/get-batch-txs)))
               final-tx-report (assoc tx-report'
                                      :tx-data full-tx-data
                                      :db-before (:db-before tx-report))
-              affected-query-keys (when-not (:importing? context)
+              affected-query-keys (when-not (or (:importing? context) now-batch-processing?)
                                     (worker-react/get-affected-queries-keys final-tx-report))]
-          (when batch-processing?
+          (when now-batch-processing?
             (batch-tx/conj-batch-txs! full-tx-data))
           {:tx-report final-tx-report
            :affected-keys affected-query-keys

+ 0 - 1
src/main/frontend/worker/state.cljs

@@ -19,7 +19,6 @@
                        :config {}
                        :git/current-repo nil
 
-                       :tx/batch-processing? false
                        :tx/batch-txs nil
 
                        :rtc/downloading-graph? false