mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
step 2: :file-sync/sync-state
This commit is contained in:
@@ -206,7 +206,7 @@
|
||||
*loading? (::loading? state)
|
||||
*exist? (::exist? state)]
|
||||
(when (and sync-on? asset-file? (false? @*exist?))
|
||||
(let [sync-state (state/sub [:file-sync/sync-state (state/get-current-repo)])
|
||||
(let [sync-state (state/get-file-sync-state (state/get-current-file-sync-graph-uuid))
|
||||
downloading-files (:current-remote->local-files sync-state)
|
||||
contain-url? (and (seq downloading-files)
|
||||
(some #(string/ends-with? src %) downloading-files))]
|
||||
@@ -220,7 +220,7 @@
|
||||
(reset! *loading? false))))))
|
||||
state)}
|
||||
[state src content-fn]
|
||||
(let [_ (state/sub [:file-sync/sync-state (state/get-current-repo)])
|
||||
(let [_ (state/sub-file-sync-state (state/get-current-file-sync-graph-uuid))
|
||||
exist? @(::exist? state)
|
||||
loading? @(::loading? state)
|
||||
asset-file? (::asset-file? state)
|
||||
|
||||
@@ -324,7 +324,7 @@
|
||||
enabled-progress-panel? (util/electron?)
|
||||
current-repo (state/get-current-repo)
|
||||
creating-remote-graph? (state/sub [:ui/loading? :graph/create-remote?])
|
||||
sync-state (state/sub [:file-sync/sync-state current-repo])
|
||||
sync-state (state/get-file-sync-state (state/get-current-file-sync-graph-uuid))
|
||||
sync-progress (state/sub [:file-sync/progress (second @fs-sync/graphs-txid)])
|
||||
_ (rum/react file-sync-handler/refresh-file-sync-component)
|
||||
synced-file-graph? (file-sync-handler/synced-file-graph? current-repo)
|
||||
@@ -367,8 +367,8 @@
|
||||
nil
|
||||
|
||||
(and synced-file-graph?
|
||||
(fs-sync/graph-sync-off? current-repo)
|
||||
(second @fs-sync/graphs-txid)
|
||||
(fs-sync/graph-sync-off? (second @fs-sync/graphs-txid))
|
||||
(async/<! (fs-sync/<check-remote-graph-exists (second @fs-sync/graphs-txid))))
|
||||
(do
|
||||
(prn "sync start")
|
||||
|
||||
@@ -1640,8 +1640,8 @@
|
||||
[type {:keys [dir path _content stat] :as _payload}]
|
||||
(when-let [current-graph (state/get-current-repo)]
|
||||
(when (string/ends-with? current-graph dir)
|
||||
(let [sync-state (state/get-file-sync-state current-graph)]
|
||||
(when (and sync-state (sync-state--valid-to-accept-filewatcher-event? sync-state))
|
||||
(when-let [sync-state (state/get-file-sync-state (state/get-current-file-sync-graph-uuid))]
|
||||
(when (sync-state--valid-to-accept-filewatcher-event? sync-state)
|
||||
(when (or (:mtime stat) (= type "unlink"))
|
||||
(go
|
||||
(let [path (remove-dir-prefix dir path)
|
||||
@@ -2869,7 +2869,7 @@
|
||||
(state/clear-file-sync-state! (:graph-uuid sm))
|
||||
|
||||
(<! (-stop! sm))
|
||||
(swap! state/state assoc :file-sync/sync-state {})
|
||||
|
||||
(println "[SyncManager" (:graph-uuid sm) "]" "stopped")
|
||||
(state/set-file-sync-manager nil)
|
||||
(clear-graph-progress! (:graph-uuid sm)))
|
||||
@@ -2919,9 +2919,9 @@
|
||||
(or (nil? sync-state) (sync-state--stopped? sync-state)))
|
||||
|
||||
(defn graph-sync-off?
|
||||
"Is sync not running for this `graph`?"
|
||||
[graph]
|
||||
(sync-off? (state/get-file-sync-state graph)))
|
||||
"Is sync not running for this `graph-uuid`?"
|
||||
[graph-uuid]
|
||||
(sync-off? (state/get-file-sync-state graph-uuid)))
|
||||
|
||||
(defn graph-encrypted?
|
||||
[]
|
||||
@@ -2957,7 +2957,7 @@
|
||||
(if-not (<! (<check-remote-graph-exists graph-uuid)) ; remote graph has been deleted
|
||||
(clear-graphs-txid! repo)
|
||||
(do
|
||||
(state/set-file-sync-state repo @*sync-state)
|
||||
(state/set-file-sync-state graph-uuid @*sync-state)
|
||||
(state/set-file-sync-manager graph-uuid sm)
|
||||
|
||||
;; update global state when *sync-state changes
|
||||
@@ -2967,6 +2967,8 @@
|
||||
|
||||
(.start sm)
|
||||
|
||||
(state/set-state! [:file-sync/graph-state :current-graph-uuid] graph-uuid)
|
||||
|
||||
(offer! remote->local-full-sync-chan true)
|
||||
(offer! full-sync-chan true)
|
||||
(swap! *sync-starting? assoc graph-uuid false))))))
|
||||
@@ -3007,7 +3009,7 @@
|
||||
(go-loop []
|
||||
(let [{{graph-uuid :graph-uuid} :data} (<! re-remote->local-full-sync-chan)
|
||||
{:keys [current-syncing-graph-uuid]}
|
||||
(state/get-file-sync-state (state/get-current-repo))]
|
||||
(state/get-file-sync-state graph-uuid)]
|
||||
(when (= graph-uuid current-syncing-graph-uuid)
|
||||
(offer! remote->local-full-sync-chan true))
|
||||
(recur)))
|
||||
@@ -3017,31 +3019,11 @@
|
||||
(async/sub sync-events-publication :local->remote-full-sync-failed re-local->remote-full-sync-chan)
|
||||
(go-loop []
|
||||
(let [{{graph-uuid :graph-uuid} :data} (<! re-local->remote-full-sync-chan)
|
||||
{:keys [current-syncing-graph-uuid]} (state/get-file-sync-state (state/get-current-repo))]
|
||||
{:keys [current-syncing-graph-uuid]} (state/get-file-sync-state graph-uuid)]
|
||||
(when (= graph-uuid current-syncing-graph-uuid)
|
||||
(offer! full-sync-chan true))
|
||||
(recur)))
|
||||
|
||||
|
||||
|
||||
;;; debug funcs
|
||||
(comment
|
||||
;; (<get-remote-all-files-meta remoteapi graph-uuid)
|
||||
(<get-local-all-files-meta rsapi graph-uuid
|
||||
(config/get-repo-dir (state/get-current-repo)))
|
||||
(def base-path (config/get-repo-dir (state/get-current-repo)))
|
||||
|
||||
;; upload
|
||||
(def full-upload-files (:full-local->remote-files (state/sub [:file-sync/sync-state (state/get-current-repo)])))
|
||||
|
||||
;; queued
|
||||
(:queued-local->remote-files (state/sub [:file-sync/sync-state (state/get-current-repo)]))
|
||||
|
||||
;; download
|
||||
(:current-remote->local-files (state/sub [:file-sync/sync-state (state/get-current-repo)]))
|
||||
)
|
||||
|
||||
|
||||
;;; add-tap
|
||||
(comment
|
||||
(def *x (atom nil))
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
(defn current-graph-sync-on?
|
||||
[]
|
||||
(when-let [sync-state (state/sub [:file-sync/sync-state (state/get-current-repo)])]
|
||||
(when-let [sync-state (state/sub-file-sync-state (state/get-current-file-sync-graph-uuid))]
|
||||
(not (sync/sync-state--stopped? sync-state))))
|
||||
|
||||
(defn synced-file-graph?
|
||||
|
||||
@@ -237,10 +237,9 @@
|
||||
{:welcome false})
|
||||
:file-sync/remote-graphs {:loading false :graphs nil}
|
||||
|
||||
;; graph-uuid -> {}
|
||||
;; graph-uuid -> [:current-graph-uuid :file-sync/sync-manager :file-sync/sync-state]
|
||||
:file-sync/graph-state {}
|
||||
|
||||
:file-sync/sync-state nil
|
||||
:file-sync/sync-uploading-files nil
|
||||
:file-sync/sync-downloading-files nil
|
||||
:file-sync/set-remote-graph-password-result {}
|
||||
@@ -1773,15 +1772,21 @@ Similar to re-frame subscriptions"
|
||||
(defn clear-file-sync-state! [graph-uuid]
|
||||
(set-state! [:file-sync/graph-state graph-uuid] nil))
|
||||
|
||||
(defn set-file-sync-state [graph v]
|
||||
(defn set-file-sync-state [graph-uuid v]
|
||||
(when v (s/assert :frontend.fs.sync/sync-state v))
|
||||
(set-state! [:file-sync/sync-state graph] v))
|
||||
(set-state! [:file-sync/graph-state graph-uuid :file-sync/sync-state] v))
|
||||
|
||||
(defn get-file-sync-state
|
||||
([]
|
||||
(get-file-sync-state (get-current-repo)))
|
||||
([repo]
|
||||
(get-in @state [:file-sync/sync-state repo])))
|
||||
[graph-uuid]
|
||||
(get-in @state [:file-sync/graph-state graph-uuid :file-sync/sync-state]))
|
||||
|
||||
(defn sub-file-sync-state
|
||||
[graph-uuid]
|
||||
(sub [:file-sync/graph-state graph-uuid :file-sync/sync-state]))
|
||||
|
||||
(defn get-current-file-sync-graph-uuid
|
||||
[]
|
||||
(get-in @state [:file-sync/graph-state :current-graph-uuid]))
|
||||
|
||||
(defn reset-parsing-state!
|
||||
[]
|
||||
|
||||
Reference in New Issue
Block a user