diff --git a/deps/common/src/logseq/common/util.cljs b/deps/common/src/logseq/common/util.cljs index 1291beff74..ebade833bf 100644 --- a/deps/common/src/logseq/common/util.cljs +++ b/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) diff --git a/src/main/frontend/util.cljc b/src/main/frontend/util.cljc index 1aa2896762..a4119be06d 100644 --- a/src/main/frontend/util.cljc +++ b/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] diff --git a/src/main/frontend/worker/batch_tx.cljs b/src/main/frontend/worker/batch_tx.cljs index 130d0cb4a3..f20c8f699d 100644 --- a/src/main/frontend/worker/batch_tx.cljs +++ b/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]