Browse Source

enhance: add :thread-api/get-rtc-graph-uuid

rcmerci 1 month ago
parent
commit
3d8d200c2c
2 changed files with 30 additions and 28 deletions
  1. 25 28
      src/main/frontend/handler/db_based/rtc.cljs
  2. 5 0
      src/main/frontend/worker/db_worker.cljs

+ 25 - 28
src/main/frontend/handler/db_based/rtc.cljs

@@ -105,42 +105,39 @@
 
 (defn <rtc-start!
   [repo & {:keys [stop-before-start?] :or {stop-before-start? true}}]
-  (let [db (db/get-db repo)
-        graph-uuid (ldb/get-graph-rtc-uuid db)]
+  (p/let [graph-uuid (state/<invoke-db-worker :thread-api/get-rtc-graph-uuid repo)]
     (if-not graph-uuid
       (log/info :skip-<rtc-start! ["graph-uuid not found" repo])
       (p/do!
-        (js/Promise. user-handler/task--ensure-id&access-token)
-        (p/let [start-ex (state/<invoke-db-worker :thread-api/rtc-start stop-before-start?)
-                ex-data* (ex-data start-ex)
-                _ (case (:type ex-data*)
-                    (:rtc.exception/not-rtc-graph
-                     :rtc.exception/not-found-db-conn)
-                    (notification/show! (ex-message start-ex) :error)
+       (js/Promise. user-handler/task--ensure-id&access-token)
+       (p/let [start-ex (state/<invoke-db-worker :thread-api/rtc-start stop-before-start?)
+               ex-data* (ex-data start-ex)
+               _ (case (:type ex-data*)
+                   (:rtc.exception/not-rtc-graph
+                    :rtc.exception/not-found-db-conn)
+                   (notification/show! (ex-message start-ex) :error)
 
-                    :rtc.exception/major-schema-version-mismatched
-                    (case (:sub-type ex-data*)
-                      :download
-                      (notification-download-higher-schema-graph! repo graph-uuid (:remote ex-data*))
-                      :create-branch
-                      (notification-upload-higher-schema-graph! repo)
+                   :rtc.exception/major-schema-version-mismatched
+                   (case (:sub-type ex-data*)
+                     :download
+                     (notification-download-higher-schema-graph! repo graph-uuid (:remote ex-data*))
+                     :create-branch
+                     (notification-upload-higher-schema-graph! repo)
                       ;; else
-                      (do (log/info :start-ex start-ex)
-                          (notification/show! [:div
-                                               [:div (ex-message start-ex)]
-                                               [:div (-> ex-data*
-                                                         (select-keys [:app :local :remote])
-                                                         pp/pprint
-                                                         with-out-str)]]
-                                              :error)))
+                     (do (log/info :start-ex start-ex)
+                         (notification/show! [:div
+                                              [:div (ex-message start-ex)]
+                                              [:div (-> ex-data*
+                                                        (select-keys [:app :local :remote])
+                                                        pp/pprint
+                                                        with-out-str)]]
+                                             :error)))
 
-                    :rtc.exception/lock-failed nil
+                   :rtc.exception/lock-failed nil
 
                     ;; else
-                    nil)]
-          nil)))
-
-    ))
+                   nil)]
+         nil)))))
 
 (defn <get-remote-graphs
   []

+ 5 - 0
src/main/frontend/worker/db_worker.cljs

@@ -774,6 +774,11 @@
   []
   @worker-state/*log)
 
+(def-thread-api :thread-api/get-rtc-graph-uuid
+  [repo]
+  (when-let [conn (worker-state/get-datascript-conn repo)]
+    (ldb/get-graph-rtc-uuid @conn)))
+
 (comment
   (def-thread-api :general/dangerousRemoveAllDbs
     []