Procházet zdrojové kódy

fix(sync): remove sync-stop in sync-start

rcmerci před 3 roky
rodič
revize
fd91db1449
1 změnil soubory, kde provedl 41 přidání a 41 odebrání
  1. 41 41
      src/main/frontend/fs/sync.cljs

+ 41 - 41
src/main/frontend/fs/sync.cljs

@@ -2934,48 +2934,48 @@
 ;; Prevent starting of multiple sync managers
 (def *sync-starting? (atom {}))
 (defn sync-start []
-  (let [*sync-state                 (atom (sync-state))
-        current-user-uuid           (user/user-uuid)
-        repo                        (state/get-current-repo)]
-    (go
-      (<! (<sync-stop))
+  (go
+    (let [*sync-state                 (atom (sync-state))
+          current-user-uuid           (user/user-uuid)
+          ;; put @graph-uuid & get-current-repo together,
+          ;; prevent to get older repo dir and current graph-uuid.
+          _                           (<! (p->c (persist-var/-load graphs-txid)))
+          [user-uuid graph-uuid txid] @graphs-txid
+          repo                        (state/get-current-repo)]
       (when (and (graph-sync-off? repo) @network-online-cursor)
-        (<! (p->c (persist-var/-load graphs-txid)))
-        (let [[user-uuid graph-uuid txid] @graphs-txid]
-          (when (and user-uuid graph-uuid txid
-                     (user/logged-in?)
-                     repo
-                     (not (config/demo-graph? repo)))
-            (try
-              (when-not (get @*sync-starting? graph-uuid)
-                (swap! *sync-starting? assoc graph-uuid true)
-
-                (when-some [sm (sync-manager-singleton current-user-uuid graph-uuid
-                                                       (config/get-repo-dir repo) repo
-                                                       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)
-                      (do
-                        (state/set-file-sync-state graph-uuid @*sync-state)
-                        (state/set-file-sync-manager graph-uuid sm)
-
-                        ;; update global state when *sync-state changes
-                        (add-watch *sync-state ::update-global-state
-                                   (fn [_ _ _ n]
-                                     (state/set-file-sync-state graph-uuid n)))
-
-                        (state/set-state! [:file-sync/graph-state :current-graph-uuid] graph-uuid)
-
-                        (.start sm)
-
-                        (offer! remote->local-full-sync-chan true)
-                        (offer! full-sync-chan true)
-                        (swap! *sync-starting? assoc graph-uuid false))))))
-              (catch :default e
-                (prn "Sync start error: ")
-                (log/error :exception e)
-                (swap! *sync-starting? assoc graph-uuid false)))))))))
+        (when (and user-uuid graph-uuid txid
+                   (user/logged-in?)
+                   repo
+                   (not (config/demo-graph? repo)))
+          (try
+            (when-not (get @*sync-starting? graph-uuid)
+              (swap! *sync-starting? assoc graph-uuid true)
+              (when-some [sm (sync-manager-singleton current-user-uuid graph-uuid
+                                                     (config/get-repo-dir repo) repo
+                                                     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)
+                    (do
+                      (state/set-file-sync-state graph-uuid @*sync-state)
+                      (state/set-file-sync-manager graph-uuid sm)
+
+                      ;; update global state when *sync-state changes
+                      (add-watch *sync-state ::update-global-state
+                                 (fn [_ _ _ n]
+                                   (state/set-file-sync-state graph-uuid n)))
+
+                      (state/set-state! [:file-sync/graph-state :current-graph-uuid] graph-uuid)
+
+                      (.start sm)
+
+                      (offer! remote->local-full-sync-chan true)
+                      (offer! full-sync-chan true)
+                      (swap! *sync-starting? assoc graph-uuid false))))))
+            (catch :default e
+              (prn "Sync start error: ")
+              (log/error :exception e)
+              (swap! *sync-starting? assoc graph-uuid false))))))))
 
 ;;; ### some add-watches