Browse Source

fix: cancel previous requests when sync needs to download/upload

This can avoid running multiple downloads/uploads at the same time.
Tienson Qin 3 years ago
parent
commit
681c3e421e
2 changed files with 7 additions and 5 deletions
  1. 0 3
      src/main/frontend/components/file_sync.cljs
  2. 7 2
      src/main/frontend/fs/sync.cljs

+ 0 - 3
src/main/frontend/components/file_sync.cljs

@@ -500,9 +500,6 @@
           ;; options
           {:outer-header
            [:<>
-            (ui/button "stop syncing"
-                       :on-click (fn []
-                                   (fs-sync/rsapi-cancel-all-requests)))
             (when (util/electron?)
               (indicator-progress-pane
                sync-state sync-progress

+ 7 - 2
src/main/frontend/fs/sync.cljs

@@ -719,6 +719,8 @@
           (recur (dec n)))
         r))))
 
+(declare rsapi-cancel-all-requests)
+
 (deftype RSAPI [^:mutable graph-uuid' ^:mutable private-key' ^:mutable public-key']
   IToken
   (<get-token [this]
@@ -766,6 +768,7 @@
   (<update-local-files [this graph-uuid base-path filepaths]
     (println "update-local-files" graph-uuid base-path filepaths)
     (go
+      (<! (rsapi-cancel-all-requests))
       (let [token (<! (<get-token this))]
         (<! (p->c (ipc/ipc "update-local-files" graph-uuid base-path filepaths token))))))
   (<download-version-files [this graph-uuid base-path filepaths]
@@ -783,6 +786,7 @@
 
   (<update-remote-files [this graph-uuid base-path filepaths local-txid]
     (go
+      (<! (rsapi-cancel-all-requests))
       (let [token (<! (<get-token this))]
         (<! (<retry-rsapi
              #(p->c (ipc/ipc "update-remote-files" graph-uuid base-path filepaths local-txid token)))))))
@@ -948,8 +952,9 @@
              nil))
 
 (defn rsapi-cancel-all-requests []
-  (when rsapi
-    (go (<! (<cancel-all-requests rsapi)))))
+  (go
+    (when rsapi
+      (<! (<cancel-all-requests rsapi)))))
 
 ;;; ### remote & rs api exceptions
 (defn sync-stop-when-api-flying?