Prechádzať zdrojové kódy

fix: ui not synced with final db

Tienson Qin 5 dní pred
rodič
commit
3af21b848d

+ 4 - 3
src/main/frontend/worker/db_sync.cljs

@@ -356,7 +356,7 @@
     (when (and conn (= local-tx remote-tx))        ; rebase
       (when (empty? inflight)
         (when-let [ws (:ws client)]
-          (when (ws-open? ws)
+          (when (and (ws-open? ws) (worker-state/online?))
             (let [batch (pending-txs repo {:limit 50})]
               (when (seq batch)
                 (let [tx-ids (mapv :tx-id batch)
@@ -596,9 +596,10 @@
                            (p/resolved nil)))))
 
 (defn- apply-remote-tx!
-  [repo client tx-data & {:keys [expected-checksum]}]
+  [repo client tx-data* & {:keys [expected-checksum]}]
   (if-let [conn (worker-state/get-datascript-conn repo)]
-    (let [local-txs (pending-txs repo)
+    (let [tx-data (keep-last-update @conn tx-data*)
+          local-txs (pending-txs repo)
           *computed-checksum (atom nil)
           reversed-tx-data (->> local-txs
                                 (mapcat :reversed-tx)

+ 4 - 2
src/main/frontend/worker/rtc/db_listener.cljs

@@ -3,7 +3,8 @@
   (:require [frontend.worker.db-listener :as db-listener]
             [frontend.worker.rtc.client-op :as client-op]
             [frontend.worker.rtc.debug-log :as rtc-debug-log]
-            [frontend.worker.rtc.gen-client-op :as gen-client-op]))
+            [frontend.worker.rtc.gen-client-op :as gen-client-op]
+            [frontend.worker.state :as worker-state]))
 
 (comment
   ;; TODO: make it a qualified-keyword
@@ -15,7 +16,8 @@
    {:keys [repo same-entity-datoms-coll id->same-entity-datoms]}
    {:keys [tx-data tx-meta db-before db-after]}]
   (when (and (client-op/rtc-db-graph? repo)
-             (:persist-op? tx-meta true))
+             (:persist-op? tx-meta true)
+             (not (:enabled? @worker-state/*db-sync-config)))
     (rtc-debug-log/log-tx! repo tx-data tx-meta)
     (let [e->a->add?->v->t (update-vals
                             id->same-entity-datoms

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

@@ -123,6 +123,10 @@
   []
   (:auth/id-token @*state))
 
+(defn online?
+  []
+  @(:thread-atom/online-event @*state))
+
 (comment
   (defn mobile?
     []