diff --git a/src/electron/electron/handler.cljs b/src/electron/electron/handler.cljs index 820f80373f..0ad88f999d 100644 --- a/src/electron/electron/handler.cljs +++ b/src/electron/electron/handler.cljs @@ -33,8 +33,7 @@ [logseq.db.sqlite.db :as sqlite-db] [logseq.db.sqlite.util :as sqlite-util] [logseq.common.graph :as common-graph] - [promesa.core :as p] - [electron.rtc-handler])) + [promesa.core :as p])) (defmethod handle :mkdir [_window [_ dir]] (fs/mkdirSync dir)) diff --git a/src/electron/electron/rtc_handler.cljs b/src/electron/electron/rtc_handler.cljs deleted file mode 100644 index 6ddccb548b..0000000000 --- a/src/electron/electron/rtc_handler.cljs +++ /dev/null @@ -1,20 +0,0 @@ -(ns electron.rtc-handler - (:require [electron.handler-interface :refer [handle]] - [electron.db :as db] - [cljs.reader :as reader] - [logseq.db.sqlite.rtc :as sqlite-rtc])) - -(defmethod handle :rtc/init [_window [_ repo]] - (sqlite-rtc/init! (db/get-graphs-dir) repo)) - -(defmethod handle :rtc/add-ops [_window [_ repo data-str]] - (let [ops (reader/read-string data-str)] - (when (seq ops) - (sqlite-rtc/add-ops! repo ops)))) - - -(defmethod handle :rtc/get-ops&local-tx [_window [_ repo]] - (sqlite-rtc/get-ops&local-tx repo)) - -(defmethod handle :rtc/clean-ops [_window [_ repo]] - (sqlite-rtc/clean-ops! repo)) diff --git a/src/main/frontend/db/rtc/core.cljs b/src/main/frontend/db/rtc/core.cljs index 486eaeabde..40fda47258 100644 --- a/src/main/frontend/db/rtc/core.cljs +++ b/src/main/frontend/db/rtc/core.cljs @@ -18,10 +18,6 @@ [frontend.db.rtc.op :as op])) -(defn init-rtc-op-db - [repo] - (when (config/db-based-graph? repo) - (ipc/ipc :rtc/init repo))) (def state-schema diff --git a/src/main/frontend/db/rtc/op.cljs b/src/main/frontend/db/rtc/op.cljs index 3fe0baeecd..2d6b1e5234 100644 --- a/src/main/frontend/db/rtc/op.cljs +++ b/src/main/frontend/db/rtc/op.cljs @@ -1,7 +1,7 @@ (ns frontend.db.rtc.op - (:require [electron.ipc :as ipc] - [malli.core :as m] - [cljs.core.async.interop :refer [p->c]])) + (:require [malli.core :as m] + [frontend.db.rtc.ops-idb-store :as op-store] + [promesa.core :as p])) (def op-schema [:or @@ -17,33 +17,34 @@ (def op-validator (m/validator op-schema)) - -(defn c (ipc/ipc :rtc/add-ops repo (pr-str [op]))))) + (op-store/c (ipc/ipc :rtc/add-ops repo (pr-str [op]))))) + (assert (op-validator op) op) + (op-store/c (ipc/ipc :rtc/add-ops repo (pr-str [op]))))) + (assert (op-validator op) op) + (op-store/c (ipc/ipc :rtc/get-ops&local-tx repo))) + (p/let [all-data (op-store/> all-data + (filter (comp number? first)) + (sort-by first <))] + {:ops ops :local-tx local-tx}))) (defn c (ipc/ipc :rtc/clean-ops repo))) - -(defn c (ipc/ipc :rtc/init repo))) + [repo keys] + (op-store/c]] - [cljs.core.async :as async :refer [poll!]])) + [cljs.core.async :as async] + [cljs.core.async.interop :refer [p->c]])) (def stores (atom {})) (defn- ensure-store - [graph-uuid] - {:pre [(some? graph-uuid)]} - (swap! stores assoc graph-uuid (Store. "rtc-ops" graph-uuid)) - (@stores graph-uuid)) + [repo] + {:pre [(some? repo)]} + (swap! stores assoc repo (Store. (str "rtc-ops-" repo) "ops")) + (@stores repo)) (defn js {:local-tx tx}) (ensure-store graph-uuid))) + [repo tx] + (idb-keyval/set "local-tx" (clj->js {:local-tx tx}) (ensure-store repo))) + +(defn js op) store)))))) + + +(def ^:private add-op-ch (async/chan 100)) +(async/go-loop [] + (if-let [[repo op] (async/c (js op) store))) + [repo op] + (async/go (async/>! add-op-ch [repo op]))) +(defn (p/all (mapv (fn [k] (p/chain (idb-keyval/get k store) (partial vector k))) keys)) (p/then (fn [items] (mapv #(js->clj % :keywordize-keys true) items)))))) diff --git a/src/main/frontend/handler.cljs b/src/main/frontend/handler.cljs index 4e24ce08f6..d0dd1565eb 100644 --- a/src/main/frontend/handler.cljs +++ b/src/main/frontend/handler.cljs @@ -88,7 +88,6 @@ (-> (db-restore/restore-graph! repo) (p/then (fn [] - (rtc-core/init-rtc-op-db repo) (db-listener/listen-and-persist! repo) ;; try to load custom css only for current repo (ui-handler/add-style-if-exists!) diff --git a/src/main/frontend/handler/repo.cljs b/src/main/frontend/handler/repo.cljs index 5e6efc6527..b62963da78 100644 --- a/src/main/frontend/handler/repo.cljs +++ b/src/main/frontend/handler/repo.cljs @@ -410,7 +410,6 @@ (p/do! (state/set-db-restoring! true) (db-restore/restore-graph! repo) - (rtc-core/init-rtc-op-db repo) (repo-config-handler/restore-repo-config! repo) (when (config/global-config-enabled?) (global-config-handler/restore-global-config!)) diff --git a/src/main/frontend/modules/outliner/core.cljs b/src/main/frontend/modules/outliner/core.cljs index 01cb745154..2a1761cce9 100644 --- a/src/main/frontend/modules/outliner/core.cljs +++ b/src/main/frontend/modules/outliner/core.cljs @@ -991,10 +991,7 @@ repo (:repo *transaction-args*) persist-op? (:persist-op? *transaction-args*)] (when (and persist-op? repo) - (async/go - (rtc-op/