mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
step 5 :graphs-txid
This commit is contained in:
@@ -360,7 +360,7 @@
|
||||
(fn []
|
||||
(when-not (file-sync-handler/current-graph-sync-on?)
|
||||
(async/go
|
||||
(let [graphs-txid fs-sync/graphs-txid]
|
||||
(let [graphs-txid (fs-sync/get-graphs-txid)]
|
||||
(async/<! (p->c (persist-var/-load graphs-txid)))
|
||||
(cond
|
||||
@*beta-unavailable?
|
||||
@@ -376,9 +376,7 @@
|
||||
(second @graphs-txid)
|
||||
(fs-sync/graph-sync-off? (second @graphs-txid))
|
||||
(async/<! (fs-sync/<check-remote-graph-exists (second @graphs-txid))))
|
||||
(do
|
||||
(prn "sync start")
|
||||
(fs-sync/sync-start))
|
||||
(fs-sync/sync-start)
|
||||
|
||||
;; remote graph already has been deleted, clear repos first, then create-remote-graph
|
||||
synced-file-graph? ; <check-remote-graph-exists -> false
|
||||
|
||||
@@ -181,28 +181,35 @@
|
||||
|
||||
(def ws-addr config/WS-URL)
|
||||
|
||||
;; Warning: make sure to `persist-var/-load` graphs-txid before using it.
|
||||
(def graphs-txid (persist-var/persist-var nil "graphs-txid"))
|
||||
|
||||
(defn get-graphs-txid
|
||||
[graph-uuid]
|
||||
;; (when graph-uuid
|
||||
;; (get @state/state [:file-sync/graph-state graph-uuid ]))
|
||||
)
|
||||
([]
|
||||
(let [result (persist-var/persist-var nil "graphs-txid")]
|
||||
(p/let [_ (persist-var/-load result)]
|
||||
(when-let [graph-uuid (second @result)]
|
||||
(state/set-state! [:file-sync/graph-state graph-uuid :graphs-txid] result)))
|
||||
result))
|
||||
([graph-uuid]
|
||||
(when graph-uuid
|
||||
(let [result (get-in @state/state [:file-sync/graph-state graph-uuid :graphs-txid]
|
||||
(get-graphs-txid))]
|
||||
(persist-var/-load result)
|
||||
result))))
|
||||
|
||||
(declare assert-local-txid<=remote-txid)
|
||||
(defn <update-graphs-txid!
|
||||
[latest-txid graph-uuid user-uuid repo]
|
||||
{:pre [(int? latest-txid) (>= latest-txid 0)]}
|
||||
(-> (p/let [_ (persist-var/-reset-value! graphs-txid [user-uuid graph-uuid latest-txid] repo)
|
||||
_ (persist-var/persist-save graphs-txid)]
|
||||
(state/pub-event! [:graph/refresh])
|
||||
(when (state/developer-mode?) (assert-local-txid<=remote-txid)))
|
||||
p->c))
|
||||
(let [graphs-txid (get-graphs-txid graph-uuid)]
|
||||
(-> (p/let [_ (persist-var/-reset-value! graphs-txid [user-uuid graph-uuid latest-txid] repo)
|
||||
_ (persist-var/persist-save graphs-txid)]
|
||||
(state/pub-event! [:graph/refresh])
|
||||
(when (state/developer-mode?) (assert-local-txid<=remote-txid)))
|
||||
p->c)))
|
||||
|
||||
(defn clear-graphs-txid! [repo]
|
||||
(persist-var/-reset-value! graphs-txid nil repo)
|
||||
(persist-var/persist-save graphs-txid))
|
||||
(defn clear-graphs-txid! [graph-uuid]
|
||||
(when-let [graphs-txid (get-graphs-txid graph-uuid)]
|
||||
(persist-var/-reset-value! graphs-txid nil (state/get-current-repo))
|
||||
(persist-var/persist-save graphs-txid)))
|
||||
|
||||
(defn- ws-ping-loop [ws]
|
||||
(go-loop []
|
||||
@@ -1366,10 +1373,11 @@
|
||||
|
||||
(defn- assert-local-txid<=remote-txid
|
||||
[]
|
||||
(when-let [local-txid (last @graphs-txid)]
|
||||
(go (let [remote-txid (:TXId (<! (<get-remote-graph remoteapi nil (second @graphs-txid))))]
|
||||
(assert (<= local-txid remote-txid)
|
||||
[@graphs-txid local-txid remote-txid])))))
|
||||
(let [graphs-txid (get-graphs-txid)]
|
||||
(when-let [local-txid (last @graphs-txid)]
|
||||
(go (let [remote-txid (:TXId (<! (<get-remote-graph remoteapi nil (second @graphs-txid))))]
|
||||
(assert (<= local-txid remote-txid)
|
||||
[@graphs-txid local-txid remote-txid]))))))
|
||||
|
||||
(defn- get-local-files-checksum
|
||||
[graph-uuid base-path relative-paths]
|
||||
@@ -2926,7 +2934,7 @@
|
||||
|
||||
(defn graph-encrypted?
|
||||
[]
|
||||
(when-let [graph-uuid (second @graphs-txid)]
|
||||
(when-let [graph-uuid (state/get-current-file-sync-graph-uuid)]
|
||||
(get-pwd graph-uuid)))
|
||||
|
||||
(declare network-online-cursor)
|
||||
@@ -2936,7 +2944,8 @@
|
||||
(defn sync-start []
|
||||
(let [*sync-state (atom (sync-state))
|
||||
current-user-uuid (user/user-uuid)
|
||||
repo (state/get-current-repo)]
|
||||
repo (state/get-current-repo)
|
||||
graphs-txid (get-graphs-txid)]
|
||||
(go
|
||||
(<! (<sync-stop))
|
||||
(when (and (graph-sync-off? repo) @network-online-cursor)
|
||||
@@ -2955,7 +2964,7 @@
|
||||
txid *sync-state)]
|
||||
(when (check-graph-belong-to-current-user current-user-uuid user-uuid)
|
||||
(if-not (<! (<check-remote-graph-exists graph-uuid)) ; remote graph has been deleted
|
||||
(clear-graphs-txid! repo)
|
||||
(clear-graphs-txid! graph-uuid)
|
||||
(do
|
||||
(state/set-file-sync-state graph-uuid @*sync-state)
|
||||
(state/set-file-sync-manager graph-uuid sm)
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
(notification/show! (str "Delete graph failed: " graph-uuid) :warning)
|
||||
(do
|
||||
(when same-graph?
|
||||
(sync/clear-graphs-txid! (state/get-current-repo))
|
||||
(sync/clear-graphs-txid! graph-uuid)
|
||||
(swap! refresh-file-sync-component not))
|
||||
(notification/show! (str "Graph deleted") :success))))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user