Browse Source

enhance: place rtc feature behind feature flag

Moved restore-graph to be first action since all user behavior comes from it.
Disabled rtc by default since rtc is currently failing to load graphs
Gabriel Horner 2 years ago
parent
commit
309826df89

+ 15 - 0
src/main/frontend/components/settings.cljs

@@ -763,6 +763,19 @@
                      :disabled    false}
                     (svg/info))}))
 
+(rum/defc rtc-enabled-switcher
+  [enabled?]
+  (ui/toggle enabled?
+             (fn []
+               (let [value (not enabled?)]
+                 (config-handler/set-config! :feature/enable-rtc? value)))
+             true))
+
+(defn rtc-switcher-row [enabled?]
+  (row-with-button-action
+   {:left-label "RTC"
+    :action (rtc-enabled-switcher enabled?)}))
+
 (rum/defc whiteboards-enabled-switcher
   [enabled?]
   (ui/toggle enabled?
@@ -1021,6 +1034,8 @@
           (ui/icon  (if logged-in? "lock-open" "lock") {:class "mr-1"}) (t :settings-page/beta-features)]]
         [:div.flex.flex-col.gap-4
          {:class (when-not user-handler/alpha-or-beta-user? "opacity-50 pointer-events-none cursor-not-allowed")}
+         (when (config/db-based-graph? current-repo)
+           (rtc-switcher-row (state/enable-rtc? current-repo)))
          (sync-switcher-row current-repo enable-sync?)
          (when (and enable-sync? (not (config/db-based-graph? current-repo)))
            (sync-diff-merge-switcher-row enable-sync-diff-merge?))

+ 1 - 1
src/main/frontend/db/listener.cljs

@@ -73,5 +73,5 @@
     (d/unlisten! conn :persistence)
     (repo-listen-to-tx! repo conn)
     (d/unlisten! conn :gen-ops)
-    (when (config/db-based-graph? repo)
+    (when (and (config/db-based-graph? repo) (state/enable-rtc? repo))
       (rtc-db-listener/listen-db-to-generate-ops repo conn))))

+ 21 - 20
src/main/frontend/db/rtc/op_mem_layer.cljs

@@ -359,26 +359,27 @@
 
 (defn <init-load-from-indexeddb!
   [repo]
-  (p/let [all-data (op-idb-layer/<read repo)
-          all-data-m (into {} all-data)
-          local-tx (get all-data-m "local-tx")
-          graph-uuid (get all-data-m "graph-uuid")
-          ops (->> all-data
-                   (filter (comp number? first))
-                   (sort-by first <)
-                   ops-from-store-coercer
-                   (map second))
-          {:keys [block-uuid->ops epoch->block-uuid-sorted-map]}
-          (add-ops-to-block-uuid->ops ops {} (sorted-map-by <))
-          r (cond-> {:block-uuid->ops block-uuid->ops
-                     :epoch->block-uuid-sorted-map epoch->block-uuid-sorted-map}
-              graph-uuid (assoc :graph-uuid graph-uuid)
-              local-tx (assoc :local-tx local-tx))]
-    (assert (ops-validator ops) ops)
-    (swap! *ops-store update repo #(-> %
-                                       (assoc :current-branch r)
-                                       (dissoc :old-branch)))
-    (prn ::<init-load-from-indexeddb! repo)))
+  (when (state/enable-rtc? repo)
+   (p/let [all-data (op-idb-layer/<read repo)
+           all-data-m (into {} all-data)
+           local-tx (get all-data-m "local-tx")
+           graph-uuid (get all-data-m "graph-uuid")
+           ops (->> all-data
+                    (filter (comp number? first))
+                    (sort-by first <)
+                    ops-from-store-coercer
+                    (map second))
+           {:keys [block-uuid->ops epoch->block-uuid-sorted-map]}
+           (add-ops-to-block-uuid->ops ops {} (sorted-map-by <))
+           r (cond-> {:block-uuid->ops block-uuid->ops
+                      :epoch->block-uuid-sorted-map epoch->block-uuid-sorted-map}
+               graph-uuid (assoc :graph-uuid graph-uuid)
+               local-tx (assoc :local-tx local-tx))]
+     (assert (ops-validator ops) ops)
+     (swap! *ops-store update repo #(-> %
+                                        (assoc :current-branch r)
+                                        (dissoc :old-branch)))
+     (prn ::<init-load-from-indexeddb! repo))))
 
 (defn <sync-to-idb-layer!
   [repo]

+ 10 - 7
src/main/frontend/handler.cljs

@@ -86,20 +86,23 @@
 (defn restore-and-setup!
   [repos]
   (when-let [repo (or (state/get-current-repo) (:url (first repos)))]
-    (-> (op-mem-layer/<init-load-from-indexeddb! repo)
+    (-> (db-restore/restore-graph! repo)
+        (p/do!
+         (repo-config-handler/start {:repo repo})
+         ;; Load after config since it is configurable
+         (op-mem-layer/<init-load-from-indexeddb! repo))
         (p/then
          (fn []
-           (db-restore/restore-graph! repo)
            (db-listener/listen-and-persist! repo)
            ;; try to load custom css only for current repo
            (ui-handler/add-style-if-exists!)
 
            (->
-            (p/do! (repo-config-handler/start {:repo repo})
-                   (when (config/global-config-enabled?)
-                     (global-config-handler/start {:repo repo}))
-                   (when (config/plugin-config-enabled?)
-                     (plugin-config-handler/start)))
+            (p/do!
+             (when (config/global-config-enabled?)
+               (global-config-handler/start {:repo repo}))
+             (when (config/plugin-config-enabled?)
+               (plugin-config-handler/start)))
             (p/finally
               (fn []
                 ;; install after config is restored

+ 1 - 1
src/main/frontend/handler/repo.cljs

@@ -406,9 +406,9 @@
   [repo]
   (p/do!
    (state/set-db-restoring! true)
-   (op-mem-layer/<init-load-from-indexeddb! repo)
    (db-restore/restore-graph! repo)
    (repo-config-handler/restore-repo-config! repo)
+   (op-mem-layer/<init-load-from-indexeddb! repo)
    (when (config/global-config-enabled?)
      (global-config-handler/restore-global-config!))
     ;; Don't have to unlisten the old listener, as it will be destroyed with the conn

+ 4 - 0
src/main/frontend/state.cljs

@@ -657,6 +657,10 @@ Similar to re-frame subscriptions"
   ([repo]
    (not (false? (:feature/enable-whiteboards? (sub-config repo))))))
 
+(defn enable-rtc?
+  [repo]
+  (:feature/enable-rtc? (sub-config repo)))
+
 (defn enable-git-auto-push?
   [repo]
   (not (false? (:git-auto-push (sub-config repo)))))