Ver Fonte

fix: keep the last repeated datom (different value) in batch tx

Tienson Qin há 1 ano atrás
pai
commit
a5a7a781eb

+ 5 - 0
deps/common/src/logseq/common/util.cljs

@@ -176,6 +176,11 @@
                  xs seen)))]
     (step (seq coll) #{})))
 
+(defn distinct-by-last-wins
+     [f col]
+     {:pre [(sequential? col)]}
+     (reverse (distinct-by f (reverse col))))
+
 (defn normalize-format
   [format]
   (case (keyword format)

+ 1 - 4
src/main/frontend/util.cljc

@@ -610,10 +610,7 @@
    (def distinct-by common-util/distinct-by))
 
 #?(:cljs
-   (defn distinct-by-last-wins
-     [f col]
-     {:pre [(sequential? col)]}
-     (reverse (distinct-by f (reverse col)))))
+   (def distinct-by-last-wins common-util/distinct-by-last-wins))
 
 (defn get-git-owner-and-repo
   [repo-url]

+ 4 - 2
src/main/frontend/worker/batch_tx.cljs

@@ -2,7 +2,8 @@
   "Batch process multiple transactions.
   When batch-processing, don't refresh ui."
   (:require [frontend.worker.state :as worker-state]
-            [frontend.schema-register :include-macros true :as sr]))
+            [frontend.schema-register :include-macros true :as sr]
+            [logseq.common.util :as common-util]))
 
 
 (sr/defkeyword :batch/txs
@@ -17,7 +18,8 @@
 (defn get-batch-txs
   []
   (->> (:batch/txs @worker-state/*state)
-       (sort-by :tx)))
+       (sort-by :tx)
+       (common-util/distinct-by-last-wins (fn [[e a _v _tx added]] [e a added]))))
 
 (defn set-batch-db-before!
   [db]