فهرست منبع

chore: debug rebased tx

Tienson Qin 1 ماه پیش
والد
کامیت
a1bfdec3ec
3فایلهای تغییر یافته به همراه11 افزوده شده و 8 حذف شده
  1. 5 5
      deps/db/src/logseq/db.cljs
  2. 4 1
      src/main/frontend/worker/sync.cljs
  3. 2 2
      src/test/frontend/worker/db_sync_sim_test.cljs

+ 5 - 5
deps/db/src/logseq/db.cljs

@@ -1,6 +1,7 @@
 (ns logseq.db
 (ns logseq.db
   "Main namespace for db fns. All fns are only for DB graphs"
   "Main namespace for db fns. All fns are only for DB graphs"
-  (:require [clojure.set :as set]
+  (:require [clojure.data :as data]
+            [clojure.set :as set]
             [clojure.string :as string]
             [clojure.string :as string]
             [clojure.walk :as walk]
             [clojure.walk :as walk]
             [datascript.conn :as dc]
             [datascript.conn :as dc]
@@ -186,7 +187,7 @@
 (defn transact-with-temp-conn!
 (defn transact-with-temp-conn!
   "Validate db and store once for a batch transaction, the `temp` conn can still load data from disk,
   "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."
   however it can't write to the disk."
-  [conn tx-meta batch-tx-fn & {:keys [listen-db filter-tx-data]}]
+  [conn tx-meta batch-tx-fn & {:keys [listen-db]}]
   (let [temp-conn (d/conn-from-db @conn)
   (let [temp-conn (d/conn-from-db @conn)
         *batch-tx-data (volatile! [])]
         *batch-tx-data (volatile! [])]
     ;; can read from disk, write is disallowed
     ;; can read from disk, write is disallowed
@@ -207,11 +208,10 @@
       (when (seq tx-data)
       (when (seq tx-data)
         ;; transact tx-data to `conn` and validate db
         ;; transact tx-data to `conn` and validate db
         (let [tx-data' (->>
         (let [tx-data' (->>
-                        (if (fn? filter-tx-data)
-                          (filter-tx-data temp-after-db tx-data)
-                          tx-data)
+                        tx-data
                         remove-conflict-datoms
                         remove-conflict-datoms
                         (db-normalize/replace-attr-retract-with-retract-entity temp-after-db))]
                         (db-normalize/replace-attr-retract-with-retract-entity temp-after-db))]
+          (prn :debug :transact-with-temp-conn :diff (data/diff (set tx-data) (set tx-data')))
           (transact! conn tx-data' tx-meta))))))
           (transact! conn tx-data' tx-meta))))))
 
 
 (def page? entity-util/page?)
 (def page? entity-util/page?)

+ 4 - 1
src/main/frontend/worker/sync.cljs

@@ -728,6 +728,7 @@
 (defn- apply-remote-tx-with-local-changes!
 (defn- apply-remote-tx-with-local-changes!
   [{:keys [conn local-txs reversed-tx-data safe-remote-tx-data remote-deleted-blocks
   [{:keys [conn local-txs reversed-tx-data safe-remote-tx-data remote-deleted-blocks
            temp-tx-meta *remote-tx-report *reversed-tx-report *remote-deleted-ids *rebase-tx-data]}]
            temp-tx-meta *remote-tx-report *reversed-tx-report *remote-deleted-ids *rebase-tx-data]}]
+  (prn :debug :apply-remote-tx-with-local-changes!)
   (let [batch-tx-meta {:rtc-tx? true}]
   (let [batch-tx-meta {:rtc-tx? true}]
     (ldb/transact-with-temp-conn!
     (ldb/transact-with-temp-conn!
      conn
      conn
@@ -766,10 +767,12 @@
 
 
 (defn- apply-remote-tx-without-local-changes!
 (defn- apply-remote-tx-without-local-changes!
   [{:keys [conn safe-remote-tx-data remote-deleted-block-ids temp-tx-meta]}]
   [{:keys [conn safe-remote-tx-data remote-deleted-block-ids temp-tx-meta]}]
+  (prn :debug :apply-remote-tx-without-local-changes!)
   (let [db @conn]
   (let [db @conn]
     (ldb/transact-with-temp-conn!
     (ldb/transact-with-temp-conn!
      conn
      conn
-     {:rtc-tx? true}
+     {:rtc-tx? true
+      :without-local-changes? true}
      (fn [temp-conn]
      (fn [temp-conn]
        (when (seq safe-remote-tx-data)
        (when (seq safe-remote-tx-data)
          (d/transact! temp-conn safe-remote-tx-data {:rtc-tx? true}))
          (d/transact! temp-conn safe-remote-tx-data {:rtc-tx? true}))

+ 2 - 2
src/test/frontend/worker/db_sync_sim_test.cljs

@@ -478,7 +478,7 @@
               (let [clients [{:repo repo-a :conn conn-a :client client-a :online? true :gen-uuid gen-uuid}]]
               (let [clients [{:repo repo-a :conn conn-a :client client-a :online? true :gen-uuid gen-uuid}]]
                 (prn :debug :phase-a)
                 (prn :debug :phase-a)
                 ;; Phase A: online
                 ;; Phase A: online
-                (dotimes [_ 40]
+                (dotimes [_ 500]
                   (let [client (first clients)]
                   (let [client (first clients)]
                     (run-ops! rng (assoc client :base-uuid base-uuid :state state-a)
                     (run-ops! rng (assoc client :base-uuid base-uuid :state state-a)
                               1
                               1
@@ -489,7 +489,7 @@
                 ;; Phase B: offline
                 ;; Phase B: offline
                 (prn :debug :phase-b-offline)
                 (prn :debug :phase-b-offline)
                 (let [clients-a [{:repo repo-a :conn conn-a :client client-a :online? false}]]
                 (let [clients-a [{:repo repo-a :conn conn-a :client client-a :online? false}]]
-                  (dotimes [_ 30]
+                  (dotimes [_ 500]
                     (run-ops! rng {:repo repo-a :conn conn-a :base-uuid base-uuid :state state-a :gen-uuid gen-uuid}
                     (run-ops! rng {:repo repo-a :conn conn-a :base-uuid base-uuid :state state-a :gen-uuid gen-uuid}
                               1
                               1
                               history
                               history