mirror of https://github.com/logseq/logseq
fix: don't start rtc for local db graphs
Also, stop rtc when switching into a local graph.pull/11055/head
parent
cd1c71291b
commit
c4e6db9afb
|
@ -585,6 +585,10 @@
|
||||||
:block/content ""
|
:block/content ""
|
||||||
:block/format :markdown})
|
:block/format :markdown})
|
||||||
|
|
||||||
|
(defn get-graph-rtc-uuid
|
||||||
|
[db]
|
||||||
|
(when db (:graph/uuid (d/entity db :graph/uuid))))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(defn db-based-graph?
|
(defn db-based-graph?
|
||||||
"Whether the current graph is db-only"
|
"Whether the current graph is db-only"
|
||||||
|
|
|
@ -154,12 +154,15 @@
|
||||||
(defn get-initial-data
|
(defn get-initial-data
|
||||||
"Returns initial data"
|
"Returns initial data"
|
||||||
[db]
|
[db]
|
||||||
(let [favorites (get-favorites db)
|
(let [idents (remove nil?
|
||||||
|
(when-let [id (:graph/uuid (d/entity db :graph/uuid))]
|
||||||
|
[{:db/ident :graph/uuid :graph/uuid id}]))
|
||||||
|
favorites (get-favorites db)
|
||||||
latest-journals (get-latest-journals db 3)
|
latest-journals (get-latest-journals db 3)
|
||||||
all-files (get-all-files db)
|
all-files (get-all-files db)
|
||||||
home-page-data (get-home-page db all-files)
|
home-page-data (get-home-page db all-files)
|
||||||
structured-blocks (get-structured-blocks db)]
|
structured-blocks (get-structured-blocks db)]
|
||||||
(concat favorites latest-journals all-files home-page-data structured-blocks)))
|
(concat idents favorites latest-journals all-files home-page-data structured-blocks)))
|
||||||
|
|
||||||
(defn restore-initial-data
|
(defn restore-initial-data
|
||||||
"Given initial sqlite data and schema, returns a datascript connection"
|
"Given initial sqlite data and schema, returns a datascript connection"
|
||||||
|
|
|
@ -23,7 +23,9 @@
|
||||||
[frontend.version :refer [version]]
|
[frontend.version :refer [version]]
|
||||||
[reitit.frontend.easy :as rfe]
|
[reitit.frontend.easy :as rfe]
|
||||||
[rum.core :as rum]
|
[rum.core :as rum]
|
||||||
[clojure.string :as string]))
|
[clojure.string :as string]
|
||||||
|
[frontend.db :as db]
|
||||||
|
[logseq.db :as ldb]))
|
||||||
|
|
||||||
(rum/defc home-button
|
(rum/defc home-button
|
||||||
< {:key-fn #(identity "home-button")}
|
< {:key-fn #(identity "home-button")}
|
||||||
|
@ -238,7 +240,8 @@
|
||||||
[:div.r.flex.drag-region
|
[:div.r.flex.drag-region
|
||||||
(when (and current-repo
|
(when (and current-repo
|
||||||
config/dev? (user-handler/logged-in?)
|
config/dev? (user-handler/logged-in?)
|
||||||
(config/db-based-graph? current-repo))
|
(config/db-based-graph? current-repo)
|
||||||
|
(some? (ldb/get-graph-rtc-uuid (db/get-db current-repo))))
|
||||||
(rtc-indicator/indicator))
|
(rtc-indicator/indicator))
|
||||||
|
|
||||||
(when (and current-repo
|
(when (and current-repo
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
[cljs-bean.core :as bean]
|
[cljs-bean.core :as bean]
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
||||||
[frontend.config :as config]
|
[frontend.config :as config]
|
||||||
[frontend.handler.user :as user-handler]))
|
[frontend.handler.user :as user-handler]
|
||||||
|
[frontend.db :as db]
|
||||||
|
[logseq.db :as ldb]))
|
||||||
|
|
||||||
(defn <rtc-create-graph!
|
(defn <rtc-create-graph!
|
||||||
[repo]
|
[repo]
|
||||||
|
@ -30,11 +32,17 @@
|
||||||
(defn <rtc-start!
|
(defn <rtc-start!
|
||||||
[repo]
|
[repo]
|
||||||
(when-let [^js worker @state/*db-worker]
|
(when-let [^js worker @state/*db-worker]
|
||||||
(user-handler/<wrap-ensure-id&access-token
|
(when (ldb/get-graph-rtc-uuid (db/get-db repo))
|
||||||
(let [token (state/get-auth-id-token)]
|
(user-handler/<wrap-ensure-id&access-token
|
||||||
(.rtc-start worker repo token
|
(let [token (state/get-auth-id-token)]
|
||||||
(and config/dev?
|
(.rtc-start worker repo token
|
||||||
(state/sub [:ui/developer-mode?])))))))
|
(and config/dev?
|
||||||
|
(state/sub [:ui/developer-mode?]))))))))
|
||||||
|
|
||||||
|
(defn <rtc-stop!
|
||||||
|
[]
|
||||||
|
(when-let [^js worker @state/*db-worker]
|
||||||
|
(.rtc-stop worker)))
|
||||||
|
|
||||||
;; TODO: shared graphs need `shared-by`, user name
|
;; TODO: shared graphs need `shared-by`, user name
|
||||||
(defn <get-remote-graphs
|
(defn <get-remote-graphs
|
||||||
|
|
|
@ -177,7 +177,9 @@
|
||||||
(srs/update-cards-due-count!)
|
(srs/update-cards-due-count!)
|
||||||
(state/pub-event! [:graph/ready graph])
|
(state/pub-event! [:graph/ready graph])
|
||||||
(if db-based?
|
(if db-based?
|
||||||
(rtc-handler/<rtc-start! graph)
|
(p/do!
|
||||||
|
(rtc-handler/<rtc-stop!)
|
||||||
|
(rtc-handler/<rtc-start! graph))
|
||||||
(file-sync-restart!))
|
(file-sync-restart!))
|
||||||
(when-let [dir-name (and (not db-based?) (config/get-repo-dir graph))]
|
(when-let [dir-name (and (not db-based?) (config/get-repo-dir graph))]
|
||||||
(fs/watch-dir! dir-name)))))))
|
(fs/watch-dir! dir-name)))))))
|
||||||
|
|
|
@ -1082,20 +1082,23 @@
|
||||||
([repo]
|
([repo]
|
||||||
(get-debug-state repo @*state))
|
(get-debug-state repo @*state))
|
||||||
([repo state]
|
([repo state]
|
||||||
(let [graph-uuid (op-mem-layer/get-graph-uuid repo)
|
(let [*conn (:*db-conn state)
|
||||||
local-tx (op-mem-layer/get-local-tx repo)
|
conn (when *conn @*conn)]
|
||||||
unpushed-block-update-count (op-mem-layer/get-unpushed-block-update-count repo)]
|
(when conn
|
||||||
(cond->
|
(let [graph-uuid (ldb/get-graph-rtc-uuid @conn)
|
||||||
{:graph-uuid graph-uuid
|
local-tx (op-mem-layer/get-local-tx repo)
|
||||||
:local-tx local-tx
|
unpushed-block-update-count (op-mem-layer/get-unpushed-block-update-count repo)]
|
||||||
:unpushed-block-update-count unpushed-block-update-count}
|
(cond->
|
||||||
state
|
{:graph-uuid graph-uuid
|
||||||
(merge
|
:local-tx local-tx
|
||||||
{:user-uuid (:user-uuid state)
|
:unpushed-block-update-count unpushed-block-update-count}
|
||||||
:rtc-state @(:*rtc-state state)
|
state
|
||||||
:ws-state (some-> @(:*ws state) ws/get-state)
|
(merge
|
||||||
:auto-push-updates? (when-let [a (:*auto-push-client-ops? state)]
|
{:user-uuid (:user-uuid state)
|
||||||
@a)})))))
|
:rtc-state @(:*rtc-state state)
|
||||||
|
:ws-state (some-> @(:*ws state) ws/get-state)
|
||||||
|
:auto-push-updates? (when-let [a (:*auto-push-client-ops? state)]
|
||||||
|
@a)})))))))
|
||||||
|
|
||||||
(defn get-block-update-log
|
(defn get-block-update-log
|
||||||
([block-uuid]
|
([block-uuid]
|
||||||
|
@ -1120,12 +1123,16 @@
|
||||||
(when reset-*state?
|
(when reset-*state?
|
||||||
(reset! *state state)
|
(reset! *state state)
|
||||||
(swap! *state update :counter inc))
|
(swap! *state update :counter inc))
|
||||||
|
(add-watch (:*rtc-state @*state) :update-rtc-state
|
||||||
|
(fn [_ _ _ _new]
|
||||||
|
(when (:*repo @*state)
|
||||||
|
(swap! *state update :counter (fnil inc 0)))))
|
||||||
state))))
|
state))))
|
||||||
|
|
||||||
(defn <start-rtc
|
(defn <start-rtc
|
||||||
[repo conn token dev-mode?]
|
[repo conn token dev-mode?]
|
||||||
(go
|
(go
|
||||||
(if-let [graph-uuid (op-mem-layer/get-graph-uuid repo)]
|
(if-let [graph-uuid (ldb/get-graph-rtc-uuid @conn)]
|
||||||
(let [state (<! (<init-state repo token true {:dev-mode? dev-mode?}))
|
(let [state (<! (<init-state repo token true {:dev-mode? dev-mode?}))
|
||||||
state-for-asset-sync (asset-sync/init-state-from-rtc-state state)
|
state-for-asset-sync (asset-sync/init-state-from-rtc-state state)
|
||||||
_ (reset! asset-sync/*asset-sync-state state-for-asset-sync)
|
_ (reset! asset-sync/*asset-sync-state state-for-asset-sync)
|
||||||
|
@ -1186,7 +1193,7 @@
|
||||||
(= :open (:rtc-state new-state)))
|
(= :open (:rtc-state new-state)))
|
||||||
(worker-util/post-message :rtc-sync-state new-state))))))
|
(worker-util/post-message :rtc-sync-state new-state))))))
|
||||||
|
|
||||||
(add-watch op-mem-layer/*ops-store :update-rtc-state
|
(add-watch op-mem-layer/*ops-store :update-ops-state
|
||||||
(fn [_ _ _ _new]
|
(fn [_ _ _ _new]
|
||||||
(when (:*repo @*state)
|
(when (:*repo @*state)
|
||||||
(swap! *state update :counter (fnil inc 0)))))
|
(swap! *state update :counter (fnil inc 0)))))
|
||||||
|
|
|
@ -128,16 +128,18 @@
|
||||||
blocks)))
|
blocks)))
|
||||||
|
|
||||||
(defn- <transact-remote-all-blocks-to-sqlite
|
(defn- <transact-remote-all-blocks-to-sqlite
|
||||||
[all-blocks repo]
|
[all-blocks repo graph-uuid]
|
||||||
(go-try
|
(go-try
|
||||||
(let [{:keys [t blocks]} all-blocks
|
(let [{:keys [t blocks]} all-blocks
|
||||||
blocks* (replace-db-id-with-temp-id blocks)
|
blocks* (replace-db-id-with-temp-id blocks)
|
||||||
blocks-with-page-id (fill-block-fields blocks*)
|
blocks-with-page-id (fill-block-fields blocks*)
|
||||||
|
tx-data (concat blocks-with-page-id
|
||||||
|
[{:db/ident :graph/uuid :graph/uuid graph-uuid}])
|
||||||
^js worker-obj (:worker/object @worker-state/*state)
|
^js worker-obj (:worker/object @worker-state/*state)
|
||||||
work (p/do!
|
work (p/do!
|
||||||
(.createOrOpenDB worker-obj repo {:close-other-db? false})
|
(.createOrOpenDB worker-obj repo {:close-other-db? false})
|
||||||
(.exportDB worker-obj repo)
|
(.exportDB worker-obj repo)
|
||||||
(.transact worker-obj repo blocks-with-page-id {:rtc-download-graph? true} (worker-state/get-context))
|
(.transact worker-obj repo tx-data {:rtc-download-graph? true} (worker-state/get-context))
|
||||||
(.closeDB worker-obj repo))]
|
(.closeDB worker-obj repo))]
|
||||||
(<? (p->c work))
|
(<? (p->c work))
|
||||||
|
|
||||||
|
@ -154,11 +156,15 @@
|
||||||
repo (str "logseq_db_" repo)]
|
repo (str "logseq_db_" repo)]
|
||||||
(if (not= 200 status)
|
(if (not= 200 status)
|
||||||
(ex-info "<download-graph failed" r)
|
(ex-info "<download-graph failed" r)
|
||||||
(let [all-blocks (transit/read transit-r body)]
|
(let [^js worker-obj (:worker/object @worker-state/*state)
|
||||||
|
all-blocks (transit/read transit-r body)]
|
||||||
(worker-state/set-rtc-downloading-graph! true)
|
(worker-state/set-rtc-downloading-graph! true)
|
||||||
(op-mem-layer/init-empty-ops-store! repo)
|
(op-mem-layer/init-empty-ops-store! repo)
|
||||||
(<? (<transact-remote-all-blocks-to-sqlite all-blocks repo))
|
(<? (<transact-remote-all-blocks-to-sqlite all-blocks repo graph-uuid))
|
||||||
(op-mem-layer/update-graph-uuid! repo graph-uuid)
|
(op-mem-layer/update-graph-uuid! repo graph-uuid)
|
||||||
(prn ::download-graph repo (@@#'op-mem-layer/*ops-store repo))
|
(prn ::download-graph repo (@@#'op-mem-layer/*ops-store repo))
|
||||||
(<! (op-mem-layer/<sync-to-idb-layer! 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))))))
|
(worker-state/set-rtc-downloading-graph! false))))))
|
||||||
|
|
|
@ -434,13 +434,6 @@
|
||||||
(assert (contains? repo-ops-store :current-branch) repo)
|
(assert (contains? repo-ops-store :current-branch) repo)
|
||||||
(asset-uuid->ops asset-uuid))))
|
(asset-uuid->ops asset-uuid))))
|
||||||
|
|
||||||
|
|
||||||
(defn get-graph-uuid
|
|
||||||
[repo]
|
|
||||||
(some-> (get @*ops-store repo)
|
|
||||||
:current-branch
|
|
||||||
:graph-uuid))
|
|
||||||
|
|
||||||
(defn get-local-tx
|
(defn get-local-tx
|
||||||
[repo]
|
[repo]
|
||||||
(some-> (get @*ops-store repo)
|
(some-> (get @*ops-store repo)
|
||||||
|
|
Loading…
Reference in New Issue