From 2e788ebb3e8fc3cca68b5d1a13d2dccc7530766a Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 2 Apr 2026 15:50:40 +0800 Subject: [PATCH] updte local checksum after recomputed --- .../frontend/handler/common/developer.cljs | 2 +- src/main/frontend/worker/db_worker.cljs | 9 +- .../handler/common/developer_test.cljs | 115 ------------------ 3 files changed, 9 insertions(+), 117 deletions(-) delete mode 100644 src/test/frontend/handler/common/developer_test.cljs diff --git a/src/main/frontend/handler/common/developer.cljs b/src/main/frontend/handler/common/developer.cljs index 3f52c3be20..cd5aa8577c 100644 --- a/src/main/frontend/handler/common/developer.cljs +++ b/src/main/frontend/handler/common/developer.cljs @@ -164,7 +164,7 @@ :local-diagnostics export-edn :server-diagnostics server-diagnostics :different-blocks diff-blocks}] - (cljs.pprint/pprint diff-data) + (pprint/pprint diff-data) (js/console.warn "Checksum mismatch between client and server. Diff data:" diff-data))) (defn ^:export recompute-checksum-diagnostics diff --git a/src/main/frontend/worker/db_worker.cljs b/src/main/frontend/worker/db_worker.cljs index e91e002efc..7e3017bf70 100644 --- a/src/main/frontend/worker/db_worker.cljs +++ b/src/main/frontend/worker/db_worker.cljs @@ -917,7 +917,14 @@ (def-thread-api :thread-api/recompute-checksum-diagnostics [repo] (when-let [conn (worker-state/get-datascript-conn repo)] - (worker-db-validate/recompute-checksum-diagnostics repo conn (sync-diagnostics-for-validation repo)))) + (let [result (worker-db-validate/recompute-checksum-diagnostics repo conn (sync-diagnostics-for-validation repo)) + recomputed-checksum (:recomputed-checksum result)] + (when (and (some? recomputed-checksum) + (worker-state/get-client-ops-conn repo)) + (client-op/update-local-checksum repo recomputed-checksum)) + (cond-> result + (some? recomputed-checksum) + (assoc :local-checksum recomputed-checksum))))) ;; Returns an export-edn map for given repo. When there's an unexpected error, a map ;; with key :export-edn-error is returned diff --git a/src/test/frontend/handler/common/developer_test.cljs b/src/test/frontend/handler/common/developer_test.cljs deleted file mode 100644 index 2227cf0a24..0000000000 --- a/src/test/frontend/handler/common/developer_test.cljs +++ /dev/null @@ -1,115 +0,0 @@ -(ns frontend.handler.common.developer-test - (:require ["/frontend/utils" :as utils] - [cljs.test :refer [async deftest is testing]] - [frontend.handler.common.developer :as developer] - [frontend.handler.db-based.sync :as db-sync-handler] - [frontend.handler.notification :as notification] - [frontend.db :as db] - [frontend.state :as state] - [logseq.db :as ldb] - [promesa.core :as p])) - -(defn- run-recompute! - ([diagnostics] - (run-recompute! diagnostics {})) - ([diagnostics {:keys [server-diagnostics]}] - (let [warnings* (atom []) - notifications* (atom []) - saves* (atom []) - fetch-calls* (atom []) - original-warn (.-warn js/console)] - (set! (.-warn js/console) (fn [& args] - (swap! warnings* conj args))) - (-> (p/with-redefs [state/get-current-repo (constantly "repo-1") - state/ (run-recompute! {:recomputed-checksum "cccccccccccccccc" - :local-checksum "aaaaaaaaaaaaaaaa" - :remote-checksum "bbbbbbbbbbbbbbbb" - :e2ee? false - :checksum-attrs [:block/title] - :blocks [{:block/uuid #uuid "00000000-0000-0000-0000-000000000001" - :block/title "local-alpha"} - {:block/uuid #uuid "00000000-0000-0000-0000-000000000002" - :block/title "local-only"}]} - {:server-diagnostics {:checksum "bbbbbbbbbbbbbbbb" - :e2ee? false - :attrs [:block/title] - :blocks [{:block/uuid "00000000-0000-0000-0000-000000000001" - :block/title "server-alpha"} - {:block/uuid "00000000-0000-0000-0000-000000000003" - :block/title "server-only"}]}}) - (p/then (fn [{:keys [warnings fetch-calls]}] - (is (= 1 (count fetch-calls))) - (is (= 1 (count warnings))) - (let [[message diff-data] (first warnings)] - (is (= "Checksum mismatch between client and server. Diff data:" message)) - (is (= "repo-1" (:repo diff-data))) - (is (= "aaaaaaaaaaaaaaaa" (:local-checksum diff-data))) - (is (= "bbbbbbbbbbbbbbbb" (:remote-checksum diff-data))) - (is (= "cccccccccccccccc" (:recomputed-checksum diff-data))) - (is (= "bbbbbbbbbbbbbbbb" (:server-checksum diff-data))) - (is (= 3 (count (:different-blocks diff-data)))) - (is (= "server-alpha" - (some->> (:different-blocks diff-data) - (filter #(= "00000000-0000-0000-0000-000000000001" - (:block/uuid %))) - first - :server-block - :block/title)))))) - (p/catch (fn [error] - (is false (str error)))) - (p/finally done)))) - -(deftest recompute-checksum-diagnostics-skips-diff-log-when-client-and-server-match-test - (async done - (-> (run-recompute! {:recomputed-checksum "aaaaaaaaaaaaaaaa" - :local-checksum "aaaaaaaaaaaaaaaa" - :remote-checksum "aaaaaaaaaaaaaaaa" - :e2ee? false - :checksum-attrs [:block/title] - :blocks []}) - (p/then (fn [{:keys [warnings fetch-calls]}] - (is (empty? warnings)) - (is (empty? fetch-calls)))) - (p/catch (fn [error] - (is false (str error)))) - (p/finally done)))) - -(deftest recompute-checksum-diagnostics-skips-diff-log-with-missing-server-checksum-test - (async done - (-> (run-recompute! {:recomputed-checksum "aaaaaaaaaaaaaaaa" - :local-checksum "aaaaaaaaaaaaaaaa" - :remote-checksum nil - :e2ee? false - :checksum-attrs [:block/title] - :blocks []}) - (p/then (fn [{:keys [warnings fetch-calls]}] - (is (empty? warnings)) - (is (empty? fetch-calls)))) - (p/catch (fn [error] - (is false (str error)))) - (p/finally done))))