Browse Source

fix: merge batch/opts and tx-meta when pass to db-listeners

rcmerci 1 year ago
parent
commit
97ef6cd37c

+ 1 - 0
src/main/frontend/worker/batch_tx.clj

@@ -9,6 +9,7 @@
   `(if (some? (frontend.worker.batch-tx/get-batch-db-before))
      (do ~@body)
      (let [tx-meta# (dissoc ~opts :additional-tx :transact-opts)]
+       (frontend.worker.batch-tx/set-batch-opts tx-meta#)
        (frontend.worker.batch-tx/set-batch-db-before! @~conn)
        ~@body
        (when (seq ~additional-tx)

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

@@ -12,6 +12,9 @@
   "store db before batch-tx.
 It can be used to judge if it is batch-processing.")
 
+(sr/defkeyword :batch/opts
+  "Opts for with-batch-tx-mode")
+
 (defn get-batch-txs
   []
   (->> (:batch/txs @worker-state/*state)
@@ -25,6 +28,14 @@ It can be used to judge if it is batch-processing.")
   []
   (:batch/db-before @worker-state/*state))
 
+(defn set-batch-opts
+  [opts]
+  (swap! worker-state/*state assoc :batch/opts opts))
+
+(defn get-batch-opts
+  []
+  (:batch/opts @worker-state/*state))
+
 (defn conj-batch-txs!
   [tx-data]
   (swap! worker-state/*state update :batch/txs (fn [data] (into data tx-data))))
@@ -32,4 +43,5 @@ It can be used to judge if it is batch-processing.")
 (defn exit-batch-txs-mode!
   []
   (swap! worker-state/*state assoc :batch/txs nil)
-  (swap! worker-state/*state assoc :batch/db-before nil))
+  (swap! worker-state/*state assoc :batch/db-before nil)
+  (swap! worker-state/*state assoc :batch/opts nil))

+ 3 - 1
src/main/frontend/worker/db_listener.cljs

@@ -68,7 +68,8 @@
     (d/unlisten! conn ::listen-db-changes!)
     (d/listen! conn ::listen-db-changes!
                (fn [{:keys [tx-data _db-before _db-after tx-meta] :as tx-report}]
-                 (let [pipeline-replace? (:pipeline-replace? tx-meta)]
+                 (let [tx-meta (merge (batch-tx/get-batch-opts) tx-meta)
+                       pipeline-replace? (:pipeline-replace? tx-meta)]
                    (when-not pipeline-replace?
                      (if-not (:batch-tx/exit? tx-meta)
                        (batch-tx/conj-batch-txs! tx-data)
@@ -90,6 +91,7 @@
                              same-entity-datoms-coll (map id->same-entity-datoms id-order)
                              id->attr->datom (update-vals id->same-entity-datoms entity-datoms=>attr->datom)
                              args* (assoc tx-report
+                                          :tx-meta tx-meta
                                           :repo repo
                                           :conn conn
                                           :id->attr->datom id->attr->datom

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

@@ -21,6 +21,7 @@
 
                        :batch/txs []
                        :batch/db-before nil
+                       :batch/opts nil
 
                        :rtc/downloading-graph? false