mirror of
https://github.com/logseq/logseq.git
synced 2026-05-23 20:24:15 +00:00
updte local checksum after recomputed
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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/<invoke-db-worker (fn [& _]
|
||||
(p/resolved diagnostics))
|
||||
utils/saveToFile (fn [& args]
|
||||
(swap! saves* conj args))
|
||||
notification/show! (fn [& args]
|
||||
(swap! notifications* conj args))
|
||||
db/get-db (fn [& _] :fake-db)
|
||||
ldb/get-graph-rtc-uuid (fn [_] "graph-1")
|
||||
db-sync-handler/http-base (fn [] "https://sync.example.test")
|
||||
db-sync-handler/fetch-json (fn [url opts schema]
|
||||
(swap! fetch-calls* conj {:url url
|
||||
:opts opts
|
||||
:schema schema})
|
||||
(p/resolved server-diagnostics))]
|
||||
(developer/recompute-checksum-diagnostics))
|
||||
(p/then (fn [_]
|
||||
{:warnings @warnings*
|
||||
:notifications @notifications*
|
||||
:saves @saves*
|
||||
:fetch-calls @fetch-calls*}))
|
||||
(p/finally (fn []
|
||||
(set! (.-warn js/console) original-warn)))))))
|
||||
|
||||
(deftest recompute-checksum-diagnostics-logs-diff-data-on-client-server-mismatch-test
|
||||
(async done
|
||||
(-> (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))))
|
||||
Reference in New Issue
Block a user