Skip to content

Commit

Permalink
Merge pull request logseq#7227 from logseq/fix/sync-crash
Browse files Browse the repository at this point in the history
fix: sync crashes
  • Loading branch information
tiensonqin authored Nov 7, 2022
2 parents b09fe61 + bf72cd6 commit daa2590
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 217 deletions.
2 changes: 1 addition & 1 deletion src/main/frontend/components/encryption.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
(if (instance? js/Error persist-r)
(js/console.error persist-r)
(when (fn? after-input-password)
(async/<! (after-input-password))
(after-input-password @*password)
;; TODO: it's better if based on sync state
(when init-graph-keys
(js/setTimeout #(state/pub-event! [:file-sync/maybe-onboarding-show :sync-learn]) 10000)))))))))))
Expand Down
6 changes: 2 additions & 4 deletions src/main/frontend/components/file_sync.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
(do
(state/set-state! [:ui/loading? :graph/create-remote?] true)
(when-let [GraphUUID (get (async/<! (file-sync-handler/create-graph graph-name)) 2)]
(async/<! (fs-sync/sync-start))
(async/<! (fs-sync/<sync-start))
(state/set-state! [:ui/loading? :graph/create-remote?] false)
;; update existing repo
(state/set-repos! (map (fn [r]
Expand Down Expand Up @@ -377,9 +377,7 @@
(second @graphs-txid)
(fs-sync/graph-sync-off? (second @graphs-txid))
(async/<! (fs-sync/<check-remote-graph-exists (second @graphs-txid))))
(do
(prn "sync start")
(fs-sync/sync-start))
(fs-sync/<sync-start)

;; remote graph already has been deleted, clear repos first, then create-remote-graph
synced-file-graph? ; <check-remote-graph-exists -> false
Expand Down
3 changes: 1 addition & 2 deletions src/main/frontend/components/header.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@
(ui/icon "chevron-left" {:size 26})])))]

[:div.r.flex
(when (and sync-enabled?
current-repo
(when (and current-repo
(not (config/demo-graph? current-repo))
(user-handler/alpha-or-beta-user?))
(fs-sync/indicator))
Expand Down
4 changes: 1 addition & 3 deletions src/main/frontend/components/settings.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,7 @@
[enabled?]
(ui/toggle enabled?
(fn []
(let [value (not enabled?)]
(storage/set :logseq-sync-enabled value)
(state/set-state! :feature/enable-sync? value)))
(file-sync-handler/set-sync-enabled! (not enabled?)))
true))

(defn sync-switcher-row [enabled?]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
(display-welcome-message)
(persist-var/load-vars)
(when config/dev?
(js/setTimeout #(sync/sync-start) 1000))))
(js/setTimeout #(sync/<sync-start) 1000))))

(defn ^:export init []
;; init is called ONCE when the page loads
Expand Down
417 changes: 213 additions & 204 deletions src/main/frontend/fs/sync.cljs

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/main/frontend/handler/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
(defn- file-sync-restart! []
(async/go (async/<! (p->c (persist-var/load-vars)))
(async/<! (sync/<sync-stop))
(some-> (sync/sync-start) async/<!)))
(some-> (sync/<sync-start) async/<!)))

(defn- file-sync-stop! []
(async/go (async/<! (p->c (persist-var/load-vars)))
Expand All @@ -86,14 +86,15 @@
(state/set-state! :user/info result)
(let [status (if (user-handler/alpha-or-beta-user?) :welcome :unavailable)]
(when (and (= status :welcome) (user-handler/logged-in?))
(file-sync-handler/set-sync-enabled! true)
(async/<! (file-sync-handler/load-session-graphs))
(p/let [repos (repo-handler/refresh-repos!)]
(when-let [repo (state/get-current-repo)]
(when (some #(and (= (:url %) repo)
(vector? (:sync-meta %))
(util/uuid-string? (first (:sync-meta %)))
(util/uuid-string? (second (:sync-meta %)))) repos)
(sync/sync-start)))))
(sync/<sync-start)))))
(ui-handler/re-render-root!)
(file-sync/maybe-onboarding-show status)))))))

Expand Down
6 changes: 6 additions & 0 deletions src/main/frontend/handler/file_sync.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
[frontend.fs :as fs]
[cljs-time.coerce :as tc]
[cljs-time.core :as t]
[frontend.storage :as storage]
[logseq.graph-parser.util :as gp-util]))

(def *beta-unavailable? (volatile! false))
Expand Down Expand Up @@ -235,3 +236,8 @@
(= mins 1) "1 min left"
(> mins 30) "calculating..."
:else (str mins " mins left"))))))

(defn set-sync-enabled!
[value]
(storage/set :logseq-sync-enabled value)
(state/set-state! :feature/enable-sync? value))

0 comments on commit daa2590

Please sign in to comment.