From 0942e86561099baebb24533127bfad6e42c03cae Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 26 Mar 2026 15:35:18 +0800 Subject: [PATCH] move checksums to sync indicator --- .../frontend/components/rtc/indicator.cljs | 8 ++++++- src/main/frontend/worker/db/validate.cljs | 23 +++---------------- src/main/frontend/worker/sync.cljs | 4 +++- src/main/frontend/worker/sync/apply_txs.cljs | 4 +++- .../frontend/worker/sync/handle_message.cljs | 4 +++- src/main/frontend/worker/sync/presence.cljs | 14 +++++++++-- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/main/frontend/components/rtc/indicator.cljs b/src/main/frontend/components/rtc/indicator.cljs index 253b5574bc..0b02dd5d3a 100644 --- a/src/main/frontend/components/rtc/indicator.cljs +++ b/src/main/frontend/components/rtc/indicator.cljs @@ -27,6 +27,8 @@ :graph-uuid nil :local-tx nil :remote-tx nil + :local-checksum nil + :remote-checksum nil :rtc-state :open :download-logs nil :upload-logs nil @@ -61,6 +63,8 @@ :graph-uuid (:graph-uuid state) :local-tx (:local-tx state) :remote-tx (:remote-tx state) + :local-checksum (:local-checksum state) + :remote-checksum (:remote-checksum state) :rtc-state (if (:rtc-lock state) :open :close))) rtc-flows/rtc-state-flow)))] (reset! *update-detail-info-canceler canceler)))) @@ -118,7 +122,7 @@ [] (let [online? (hooks/use-flow-state flows/network-online-event-flow) [expand-debug? set-expand-debug!] (hooks/use-state false) - {:keys [graph-uuid local-tx remote-tx rtc-state + {:keys [graph-uuid local-tx remote-tx local-checksum remote-checksum rtc-state download-logs upload-logs misc-logs pending-local-ops pending-server-ops]} (hooks/use-flow-state (m/watch *detail-info))] [:div.rtc-info.flex.flex-col.gap-1.p-2.text-gray-11 @@ -144,6 +148,8 @@ graph-uuid (assoc :graph-uuid graph-uuid) local-tx (assoc :local-tx local-tx) remote-tx (assoc :remote-tx remote-tx) + local-checksum (assoc :local-checksum local-checksum) + remote-checksum (assoc :remote-checksum remote-checksum) rtc-state (assoc :rtc-state rtc-state)) pprint/pprint with-out-str)]]) diff --git a/src/main/frontend/worker/db/validate.cljs b/src/main/frontend/worker/db/validate.cljs index 4a06a533e2..04fcbac292 100644 --- a/src/main/frontend/worker/db/validate.cljs +++ b/src/main/frontend/worker/db/validate.cljs @@ -219,23 +219,10 @@ :db/index true}] {:fix-db? true}))) -(defn- normalize-sync-diagnostics - [sync-diagnostics] - (merge {:local-checksum nil - :remote-checksum nil - :local-tx nil - :remote-tx nil} - (select-keys sync-diagnostics [:local-checksum :remote-checksum :local-tx :remote-tx]))) - -(defn- with-sync-diagnostics - [message sync-diagnostics] - (str message "\n\n" - "Sync diagnostics: " (pr-str (normalize-sync-diagnostics sync-diagnostics)))) - (defn validate-db ([conn] (validate-db nil conn nil)) - ([_repo conn sync-diagnostics] + ([_repo conn _options] (fix-extends-cardinality! conn) (fix-icon-wrong-type! conn) (db-migrate/ensure-built-in-data-exists! conn) @@ -258,15 +245,11 @@ {:msg "Validation errors" :errors errors}]) (shared-service/broadcast-to-clients! :notification - [(with-sync-diagnostics - (str "Validation detected " (count errors) " invalid block(s). These blocks may be buggy. Attempting to fix invalid blocks. Run validation again to see if they were fixed.") - sync-diagnostics) + [(str "Validation detected " (count errors) " invalid block(s). These blocks may be buggy. Attempting to fix invalid blocks. Run validation again to see if they were fixed.") :warning false])) (shared-service/broadcast-to-clients! :notification - [(with-sync-diagnostics - (str "Your graph is valid! " (assoc (db-validate/graph-counts db entities) :datoms datom-count)) - sync-diagnostics) + [(str "Your graph is valid! " (assoc (db-validate/graph-counts db entities) :datoms datom-count)) :success false])) {:errors errors :datom-count datom-count diff --git a/src/main/frontend/worker/sync.cljs b/src/main/frontend/worker/sync.cljs index 4362da75a9..1ad2b967ea 100644 --- a/src/main/frontend/worker/sync.cljs +++ b/src/main/frontend/worker/sync.cljs @@ -44,8 +44,10 @@ :get-pending-local-tx-count client-op/get-pending-local-tx-count :get-unpushed-asset-ops-count client-op/get-unpushed-asset-ops-count :get-local-tx client-op/get-local-tx + :get-local-checksum client-op/get-local-checksum :get-graph-uuid client-op/get-graph-uuid - :latest-remote-tx @*repo->latest-remote-tx} + :latest-remote-tx @*repo->latest-remote-tx + :latest-remote-checksum @*repo->latest-remote-checksum} repo)) (defn update-local-sync-checksum! diff --git a/src/main/frontend/worker/sync/apply_txs.cljs b/src/main/frontend/worker/sync/apply_txs.cljs index e8d06d5d7b..8c4f5d4779 100644 --- a/src/main/frontend/worker/sync/apply_txs.cljs +++ b/src/main/frontend/worker/sync/apply_txs.cljs @@ -53,8 +53,10 @@ :get-pending-local-tx-count client-op/get-pending-local-tx-count :get-unpushed-asset-ops-count client-op/get-unpushed-asset-ops-count :get-local-tx client-op/get-local-tx + :get-local-checksum client-op/get-local-checksum :get-graph-uuid client-op/get-graph-uuid - :latest-remote-tx @*repo->latest-remote-tx} + :latest-remote-tx @*repo->latest-remote-tx + :latest-remote-checksum @*repo->latest-remote-checksum} repo)) (defn- broadcast-rtc-state! [client] diff --git a/src/main/frontend/worker/sync/handle_message.cljs b/src/main/frontend/worker/sync/handle_message.cljs index 4195d10d78..eabdaeebcb 100644 --- a/src/main/frontend/worker/sync/handle_message.cljs +++ b/src/main/frontend/worker/sync/handle_message.cljs @@ -31,8 +31,10 @@ :get-pending-local-tx-count client-op/get-pending-local-tx-count :get-unpushed-asset-ops-count client-op/get-unpushed-asset-ops-count :get-local-tx client-op/get-local-tx + :get-local-checksum client-op/get-local-checksum :get-graph-uuid client-op/get-graph-uuid - :latest-remote-tx @sync-apply/*repo->latest-remote-tx} + :latest-remote-tx @sync-apply/*repo->latest-remote-tx + :latest-remote-checksum @sync-apply/*repo->latest-remote-checksum} repo)) (defn- broadcast-rtc-state! diff --git a/src/main/frontend/worker/sync/presence.cljs b/src/main/frontend/worker/sync/presence.cljs index 3e8ec8a2e7..7f6354c236 100644 --- a/src/main/frontend/worker/sync/presence.cljs +++ b/src/main/frontend/worker/sync/presence.cljs @@ -19,8 +19,10 @@ get-pending-local-tx-count get-unpushed-asset-ops-count get-local-tx + get-local-checksum get-graph-uuid - latest-remote-tx]} + latest-remote-tx + latest-remote-checksum]} repo] (when (get-datascript-conn repo) (let [pending-local (if get-pending-local-tx-count @@ -30,6 +32,9 @@ pending-asset (get-unpushed-asset-ops-count repo) local-tx (get-local-tx repo) remote-tx (get latest-remote-tx repo) + local-checksum (when get-local-checksum + (get-local-checksum repo)) + remote-checksum (get latest-remote-checksum repo) pending-server (when (and (number? local-tx) (number? remote-tx)) (max 0 (- remote-tx local-tx))) graph-uuid (get-graph-uuid repo)] @@ -38,6 +43,8 @@ :pending-server pending-server :local-tx local-tx :remote-tx remote-tx + :local-checksum local-checksum + :remote-checksum remote-checksum :graph-uuid graph-uuid}))) (defn normalize-online-users @@ -57,7 +64,8 @@ (let [repo (:repo client) ws-state @(:ws-state client) online-users @(:online-users client) - {:keys [pending-local pending-asset pending-server local-tx remote-tx graph-uuid]} + {:keys [pending-local pending-asset pending-server + local-tx remote-tx local-checksum remote-checksum graph-uuid]} (sync-counts-f repo)] {:rtc-state {:ws-state ws-state} :rtc-lock (= :open ws-state) @@ -67,6 +75,8 @@ :pending-server-ops-count (or pending-server 0) :local-tx local-tx :remote-tx remote-tx + :local-checksum local-checksum + :remote-checksum remote-checksum :graph-uuid graph-uuid})) (defn set-ws-state!