Skip to content

Commit

Permalink
fix: only periodically push current repo
Browse files Browse the repository at this point in the history
  • Loading branch information
gyk committed Dec 4, 2020
1 parent b43ca56 commit 367f288
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/main/frontend/components/repo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
(fn [{:keys [id url]}]
{:title (get-repo-name url)
:options {:on-click (fn []
(repo-handler/push-if-auto-enabled! (state/get-current-repo))
(state/set-current-repo! url)
(when-not (= :draw (state/get-current-route))
(route-handler/redirect-to-home!))
Expand Down
4 changes: 1 addition & 3 deletions src/main/frontend/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@

(defn git-pull-secs
[]
(if dev?
(* 60 5)
(or 60 (get-in @state/state [:config :git-pull-secs]))))
(or 60 (get-in @state/state [:config :git-pull-secs])))

(defn git-push-secs
[]
Expand Down
34 changes: 14 additions & 20 deletions src/main/frontend/handler/repo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -474,26 +474,20 @@
(js/setTimeout setup-local-repo-if-not-exists! 100)))

(defn periodically-pull
[repo-url pull-now?]
[repo-url {:keys [pull-now?]
:or {pull-now? true}}]
(spec/validate :repos/url repo-url)
(p/let [token (helper/get-github-token repo-url)]
(when token
(when pull-now? (pull repo-url nil))
(js/setInterval #(pull repo-url nil)
(* (config/git-pull-secs) 1000)))))

(defn periodically-push-tasks
[repo-url]
(js/setInterval #(push-if-auto-enabled! repo-url)
(defn periodically-push-current-repo
[]
(js/setInterval #(push-if-auto-enabled! (state/get-current-repo))
(* (config/git-push-secs) 1000)))

(defn periodically-pull-and-push
[repo-url {:keys [pull-now?]
:or {pull-now? true}}]
(spec/validate :repos/url repo-url)
(periodically-pull repo-url pull-now?)
(periodically-push-tasks repo-url))

(defn create-repo!
[repo-url branch]
(spec/validate :repos/url repo-url)
Expand All @@ -509,16 +503,13 @@
(println "Something wrong!")
(js/console.dir error))))

(defn- clone-and-pull
(defn- clone-and-load-db
[repo-url]
(spec/validate :repos/url repo-url)
(->
(p/let [_ (clone repo-url)
_ (git-handler/git-set-username-email! repo-url (state/get-me))]
(load-db-and-journals! repo-url nil true)
(periodically-pull-and-push repo-url {:pull-now? false})
;; (periodically-persist-app-metadata repo-url)
)
(load-db-and-journals! repo-url nil true))
(p/catch (fn [error]
(js/console.error error)))))

Expand All @@ -535,10 +526,13 @@
(db/cloned? repo))
(do
(git-handler/git-set-username-email! repo me)
(periodically-pull-and-push repo {:pull-now? true})
(periodically-pull repo {:pull-now? true})
;; (periodically-persist-app-metadata repo)
)
(clone-and-pull repo)))))
)
(do
(clone-and-load-db repo)
(periodically-pull repo {:pull-now? false})))
(periodically-push-current-repo))))
(js/setTimeout (fn []
(clone-and-pull-repos me))
500)))
Expand All @@ -551,7 +545,7 @@
(-> (p/do! (db/remove-db! url)
(db/remove-files-db! url)
(fs/rmdir (util/get-repo-dir url))
(clone-and-pull url))
(clone-and-load-db url))
(p/catch (fn [error]
(prn "Delete repo failed, error: " error)))))

Expand Down

0 comments on commit 367f288

Please sign in to comment.