diff --git a/deps/db/src/logseq/db.cljs b/deps/db/src/logseq/db.cljs index ed0e99234a..8be9bbd9ac 100644 --- a/deps/db/src/logseq/db.cljs +++ b/deps/db/src/logseq/db.cljs @@ -176,14 +176,23 @@ ;; Because UI assumes that the in-memory db has all the data except the last one transaction (when (seq tx-data) - ;; (prn :debug :transact :sync? (= d/transact! (or @*transact-fn d/transact!)) :tx-meta tx-meta) - ;; (cljs.pprint/pprint tx-data) + (prn :debug :transact :sync? (= d/transact! (or @*transact-fn d/transact!)) :tx-meta tx-meta) + (cljs.pprint/pprint tx-data) ;; (js/console.trace) (if-let [transact-fn @*transact-fn] (transact-fn repo-or-conn tx-data tx-meta) (transact-sync repo-or-conn tx-data tx-meta)))))) +(defn remove-conflict-datoms + [datoms] + (->> datoms + (group-by (fn [d] (take 4 d))) ; group by '(e a v tx) + (keep (fn [[_eavt same-eavt-datoms]] + (first (rseq same-eavt-datoms)))) + ;; sort by :tx, use nth to make this fn works on both vector and datom + (sort-by #(nth % 3)))) + (defn transact-with-temp-conn! "Validate db and store once for a batch transaction, the `temp` conn can still load data from disk, however it can't write to the disk." @@ -207,9 +216,11 @@ (vreset! *batch-tx-data nil) (when (seq tx-data) ;; transact tx-data to `conn` and validate db - (let [tx-data' (if (fn? filter-tx-data) - (filter-tx-data temp-after-db tx-data) - tx-data)] + (let [tx-data' (->> + (if (fn? filter-tx-data) + (filter-tx-data temp-after-db tx-data) + tx-data) + remove-conflict-datoms)] (transact! conn tx-data' tx-meta)))))) (def page? common-entity-util/page?) diff --git a/src/main/frontend/worker/db_sync.cljs b/src/main/frontend/worker/db_sync.cljs index ba338e0507..674a4b3fc6 100644 --- a/src/main/frontend/worker/db_sync.cljs +++ b/src/main/frontend/worker/db_sync.cljs @@ -1182,7 +1182,6 @@ (delete-nodes! temp-conn deleted-nodes (assoc temp-tx-meta :op :delete-blocks)))))) remote-tx-report @*remote-tx-report] - ;; persist rebase tx to client ops (when has-local-changes? (when-let [tx-data (seq @*rebase-tx-data)] @@ -1263,9 +1262,7 @@ tx* (if aes-key (> datoms - (group-by (fn [d] (take 4 d))) ; group by '(e a v tx) - (keep (fn [[_eavt same-eavt-datoms]] - (first (rseq same-eavt-datoms)))) - ;; sort by :tx, use nth to make this fn works on both vector and datom - (sort-by #(nth % 3)))) - (defn transact-pipeline "Compute extra tx-data and block/refs, should ensure it's a pure function and doesn't call `d/transact!` or `ldb/transact!`." - [repo {:keys [db-after tx-meta tx-data] :as tx-report}] + [repo {:keys [db-after tx-meta _tx-data] :as tx-report}] (when-not (:temp-conn? tx-meta) (let [extra-tx-data (compute-extra-tx-data tx-report) tx-report* (if (seq extra-tx-data) @@ -495,7 +486,7 @@ tx-report' (or replace-tx-report tx-report*) full-tx-data (-> (concat (:tx-data tx-report*) (:tx-data replace-tx-report)) - remove-conflict-datoms)] + ldb/remove-conflict-datoms)] (assoc tx-report' :tx-data full-tx-data :tx-meta tx-meta diff --git a/src/test/frontend/worker/pipeline_test.cljs b/src/test/frontend/worker/pipeline_test.cljs index d3d70ac95c..454ceb5efa 100644 --- a/src/test/frontend/worker/pipeline_test.cljs +++ b/src/test/frontend/worker/pipeline_test.cljs @@ -15,14 +15,14 @@ (is (= (set [[1 :a 1 1] [1 :a 2 1] [2 :a 1 1]]) - (set (#'worker-pipeline/remove-conflict-datoms datoms)))))) + (set (ldb/remove-conflict-datoms datoms)))))) (testing "check block/tags" (let [datoms [[163 :block/tags 2 536870930 true] [163 :block/tags 136 536870930 true] [163 :block/tags 136 536870930 false]]] (is (= (set [[163 :block/tags 2 536870930 true] [163 :block/tags 136 536870930 false]]) - (set (#'worker-pipeline/remove-conflict-datoms datoms)))))) + (set (ldb/remove-conflict-datoms datoms)))))) (testing "check block/refs" (let [datoms [[176 :block/refs 177 536871080 true] [158 :block/refs 21 536871082 false] @@ -39,7 +39,7 @@ [176 :block/refs 177 536871082 true] [177 :block/refs 136 536871082 true] [177 :block/refs 21 536871082 true]]) - (set (#'worker-pipeline/remove-conflict-datoms datoms))))))) + (set (ldb/remove-conflict-datoms datoms))))))) (deftest test-built-in-page-updates-that-should-be-reverted (let [graph test-helper/test-db-name-db-version