|
@@ -52,7 +52,12 @@
|
|
|
;; and re-produce a new same-file-delete diff.
|
|
|
|
|
|
;;; ### specs
|
|
|
-(s/def ::state #{::idle
|
|
|
+(s/def ::state #{;; do following jobs when ::starting:
|
|
|
+ ;; - wait seconds for file-change-events from file-watcher
|
|
|
+ ;; - drop redundant file-change-events
|
|
|
+ ;; - setup states in `frontend.state`
|
|
|
+ ::starting
|
|
|
+ ::idle
|
|
|
;; sync local-changed files
|
|
|
::local->remote
|
|
|
;; sync remote latest-transactions
|
|
@@ -847,7 +852,7 @@
|
|
|
"create a new sync-state"
|
|
|
[]
|
|
|
{:post [(s/valid? ::sync-state %)]}
|
|
|
- {:state ::idle
|
|
|
+ {:state ::starting
|
|
|
:current-local->remote-files #{}
|
|
|
:current-remote->local-files #{}
|
|
|
:queued-local->remote-files #{}
|
|
@@ -1417,24 +1422,34 @@
|
|
|
;; 1. if remote graph has been deleted, clear graphs-txid.edn
|
|
|
;; 2. if graphs-txid.edn's content isn't [user-uuid graph-uuid txid], clear it
|
|
|
(if (not= 3 (count @graphs-txid))
|
|
|
- (clear-graphs-txid! repo)
|
|
|
+ (do (clear-graphs-txid! repo)
|
|
|
+ (state/set-file-sync-state nil))
|
|
|
(when (check-graph-belong-to-current-user current-user-uuid user-uuid)
|
|
|
(if-not (<! (check-remote-graph-exists graph-uuid))
|
|
|
(clear-graphs-txid! repo)
|
|
|
(do
|
|
|
;; set-env
|
|
|
(set-env rsapi config/FILE-SYNC-PROD?)
|
|
|
-
|
|
|
+ (state/set-file-sync-state @*sync-state)
|
|
|
+ (state/set-file-sync-manager sm)
|
|
|
+ ;; wait seconds to receive all file change events,
|
|
|
+ ;; and then drop all of them.
|
|
|
+ ;; WHY: when opening a graph(or switching to another graph),
|
|
|
+ ;; file-watcher will send a lot of file-change-events,
|
|
|
+ ;; actually, each file corresponds to a file-change-event,
|
|
|
+ ;; we need to ignore all of them.
|
|
|
+ (<! (timeout 5000))
|
|
|
(drain-chan local-changes-chan)
|
|
|
(poll! stop-sync-chan)
|
|
|
(poll! remote->local-sync-chan)
|
|
|
+
|
|
|
;; update global state when *sync-state changes
|
|
|
(add-watch *sync-state ::update-global-state
|
|
|
(fn [_ _ _ n]
|
|
|
(state/set-file-sync-state n)))
|
|
|
(.start sm)
|
|
|
|
|
|
- (state/set-file-sync-manager sm)
|
|
|
+
|
|
|
(offer! remote->local-sync-chan true)
|
|
|
(offer! full-sync-chan true)
|
|
|
|