Explorar o código

fix: load rtc graphs after app starts

Tienson Qin hai 1 ano
pai
achega
1f6ec7c3bc

+ 5 - 4
src/main/frontend/components/repo.cljs

@@ -187,15 +187,16 @@
                            :options      {:on-click (fn [e]
                                                       (when-let [on-click (:on-click opts)]
                                                         (on-click e))
-                                                      (if (gobj/get e "shiftKey")
+                                                      (if (and (gobj/get e "shiftKey")
+                                                               (not (and rtc-graph? remote?)))
                                                         (state/pub-event! [:graph/open-new-window url])
                                                         (cond
-                                                          (or local? db-only?)
-                                                          (state/pub-event! [:graph/switch url])
-
                                                           (and rtc-graph? remote?)
                                                           (state/pub-event! [:rtc/download-remote-graph GraphName GraphUUID])
 
+                                                          (or local? db-only?)
+                                                          (state/pub-event! [:graph/switch url])
+
                                                           :else
                                                           (state/pub-event! [:graph/pull-down-remote-graph graph]))))}})))
                     switch-repos)

+ 16 - 15
src/main/frontend/handler/db_based/rtc.cljs

@@ -54,21 +54,22 @@
 ;; TODO: shared graphs need `shared-by`, user name
 (defn <get-remote-graphs
   []
-  (when-let [^js worker @state/*db-worker]
+  (let [^js worker @state/*db-worker]
     (user-handler/<wrap-ensure-id&access-token
      (let [repo (state/get-current-repo)
            token (state/get-auth-id-token)]
-       (p/let [result (.rtc-get-graphs worker repo token)
-               graphs (bean/->clj result)
-               result (->> graphs
-                           (remove (fn [graph]
-                                     (= (:graph-status graph) "deleting")))
-                           (mapv (fn [graph]
-                                   (merge
-                                    {:GraphName (or (:graph-name graph)
-                                                   ;; FIXME: remove this later
-                                                    (str (:graph-uuid graph)))
-                                     :GraphUUID (:graph-uuid graph)
-                                     :rtc-graph? true}
-                                    (dissoc graph :graph-uuid :graph-name)))))]
-         (state/set-state! :rtc/graphs result))))))
+       (when worker
+         (p/let [result (.rtc-get-graphs worker repo token)
+                 graphs (bean/->clj result)
+                 result (->> graphs
+                             (remove (fn [graph]
+                                       (= (:graph-status graph) "deleting")))
+                             (mapv (fn [graph]
+                                     (merge
+                                      (let [url (str config/db-version-prefix (:graph-name graph))]
+                                        {:url url
+                                         :GraphName (:graph-name graph)
+                                         :GraphUUID (:graph-uuid graph)
+                                         :rtc-graph? true})
+                                      (dissoc graph :graph-uuid :graph-name)))))]
+           (state/set-state! :rtc/graphs result)))))))

+ 4 - 3
src/main/frontend/handler/events.cljs

@@ -117,13 +117,14 @@
           (let [status (if (user-handler/alpha-or-beta-user?) :welcome :unavailable)]
             (when (and (= status :welcome) (user-handler/logged-in?))
               (enable-beta-features!)
+              (async/<! (rtc-handler/<get-remote-graphs))
               (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)
+                                    (vector? (:sync-meta %))
+                                    (util/uuid-string? (first (:sync-meta %)))
+                                    (util/uuid-string? (second (:sync-meta %)))) repos)
                     (sync/<sync-start)))))
             (ui-handler/re-render-root!)
             (file-sync/maybe-onboarding-show status)))))))

+ 18 - 20
src/main/frontend/worker/rtc/full_upload_download_graph.cljs

@@ -148,23 +148,21 @@
 
 (defn <download-graph
   [state repo graph-uuid]
-  (go-try
-   (let [{:keys [url]}
-         (<? (ws/<send&receive state {:action "full-download-graph"
-                                      :graph-uuid graph-uuid}))
-         {:keys [status body] :as r} (<! (http/get url))
-         repo (str "logseq_db_" repo)]
-     (if (not= 200 status)
-       (ex-info "<download-graph failed" r)
-       (let [^js worker-obj (:worker/object @worker-state/*state)
-             all-blocks (transit/read transit-r body)]
-         (worker-state/set-rtc-downloading-graph! true)
-         (op-mem-layer/init-empty-ops-store! repo)
-         (<? (<transact-remote-all-blocks-to-sqlite all-blocks repo graph-uuid))
-         (op-mem-layer/update-graph-uuid! repo graph-uuid)
-         (prn ::download-graph repo (@@#'op-mem-layer/*ops-store repo))
-         (<! (op-mem-layer/<sync-to-idb-layer! repo))
-         (<! (p->c
-              (p/do!
-               (.storeMetadata worker-obj repo (pr-str {:graph/uuid (:graph-uuid r)})))))
-         (worker-state/set-rtc-downloading-graph! false))))))
+  (let [^js worker-obj (:worker/object @worker-state/*state)]
+    (go-try
+     (let [{:keys [url]}
+           (<? (ws/<send&receive state {:action "full-download-graph"
+                                        :graph-uuid graph-uuid}))
+           {:keys [status body] :as r} (<! (http/get url))
+           repo (str "logseq_db_" repo)]
+       (if (not= 200 status)
+         (ex-info "<download-graph failed" r)
+         (let [all-blocks (transit/read transit-r body)]
+           (worker-state/set-rtc-downloading-graph! true)
+           (op-mem-layer/init-empty-ops-store! repo)
+           (<? (<transact-remote-all-blocks-to-sqlite all-blocks repo graph-uuid))
+           (op-mem-layer/update-graph-uuid! repo graph-uuid)
+           (prn ::download-graph repo (@@#'op-mem-layer/*ops-store repo))
+           (<! (op-mem-layer/<sync-to-idb-layer! repo))
+           (<! (p->c (.storeMetadata worker-obj repo (pr-str {:graph/uuid graph-uuid}))))
+           (worker-state/set-rtc-downloading-graph! false)))))))