|
@@ -208,6 +208,24 @@
|
|
|
true
|
|
true
|
|
|
(true? graph-e2ee?)))
|
|
(true? graph-e2ee?)))
|
|
|
|
|
|
|
|
|
|
+(defn- <wait-for-db-worker-ready!
|
|
|
|
|
+ []
|
|
|
|
|
+ (if @state/*db-worker
|
|
|
|
|
+ (p/resolved true)
|
|
|
|
|
+ (let [ready (p/deferred)
|
|
|
|
|
+ watch-key (keyword "frontend.handler.db-based.sync"
|
|
|
|
|
+ (str "wait-db-worker-ready-" (random-uuid)))]
|
|
|
|
|
+ (add-watch state/*db-worker watch-key
|
|
|
|
|
+ (fn [_ _ _ worker]
|
|
|
|
|
+ (when worker
|
|
|
|
|
+ (remove-watch state/*db-worker watch-key)
|
|
|
|
|
+ (p/resolve! ready true))))
|
|
|
|
|
+ ;; If worker becomes ready between the initial check and add-watch.
|
|
|
|
|
+ (when @state/*db-worker
|
|
|
|
|
+ (remove-watch state/*db-worker watch-key)
|
|
|
|
|
+ (p/resolve! ready true))
|
|
|
|
|
+ ready)))
|
|
|
|
|
+
|
|
|
(defn <rtc-stop!
|
|
(defn <rtc-stop!
|
|
|
[]
|
|
[]
|
|
|
(log/info :db-sync/stop true)
|
|
(log/info :db-sync/stop true)
|
|
@@ -215,15 +233,16 @@
|
|
|
|
|
|
|
|
(defn <rtc-start!
|
|
(defn <rtc-start!
|
|
|
[repo & {:keys [_stop-before-start?] :as _opts}]
|
|
[repo & {:keys [_stop-before-start?] :as _opts}]
|
|
|
- (if (should-start-rtc? repo)
|
|
|
|
|
- (do
|
|
|
|
|
- (log/info :db-sync/start {:repo repo})
|
|
|
|
|
- (state/<invoke-db-worker :thread-api/db-sync-start repo))
|
|
|
|
|
- (do
|
|
|
|
|
- (log/info :db-sync/skip-start {:repo repo :reason :graph-not-in-remote-list
|
|
|
|
|
- :remote-graphs-loading? (:rtc/loading-graphs? @state/state)
|
|
|
|
|
- :has-local-rtc-id? (graph-has-local-rtc-id? repo)})
|
|
|
|
|
- (<rtc-stop!))))
|
|
|
|
|
|
|
+ (p/let [_ (<wait-for-db-worker-ready!)]
|
|
|
|
|
+ (if (should-start-rtc? repo)
|
|
|
|
|
+ (do
|
|
|
|
|
+ (log/info :db-sync/start {:repo repo})
|
|
|
|
|
+ (state/<invoke-db-worker :thread-api/db-sync-start repo))
|
|
|
|
|
+ (do
|
|
|
|
|
+ (log/info :db-sync/skip-start {:repo repo :reason :graph-not-in-remote-list
|
|
|
|
|
+ :remote-graphs-loading? (:rtc/loading-graphs? @state/state)
|
|
|
|
|
+ :has-local-rtc-id? (graph-has-local-rtc-id? repo)})
|
|
|
|
|
+ (<rtc-stop!)))))
|
|
|
|
|
|
|
|
(defonce ^:private debounced-update-presence
|
|
(defonce ^:private debounced-update-presence
|
|
|
(util/debounce
|
|
(util/debounce
|