Selaa lähdekoodia

remove dependencies on full_upload_download_graph

Tienson Qin 1 vuosi sitten
vanhempi
sitoutus
81757c4e37

+ 10 - 4
src/main/frontend/db_worker.cljs

@@ -262,10 +262,16 @@
    (when repo (state/set-db-latest-tx-time! repo))
    (when-let [conn (state/get-datascript-conn repo)]
      (try
-       (let [tx-data (edn/read-string tx-data)
-             tx-meta (edn/read-string tx-meta)
-             context (edn/read-string context)
-             _ (state/set-context! context)
+       (let [tx-data (if (string? tx-data)
+                       (edn/read-string tx-data)
+                       tx-data)
+             tx-meta (if (string? tx-meta)
+                       (edn/read-string tx-meta)
+                       tx-meta)
+             context (if (string? context)
+                       (edn/read-string context)
+                       context)
+             _ (when context (state/set-context! context))
              tx-meta' (if (or (:from-disk? tx-meta) (:new-graph? tx-meta))
                         tx-meta
                         (assoc tx-meta :skip-store? true))

+ 5 - 1
src/main/frontend/handler/worker.cljs

@@ -3,7 +3,8 @@
   (:require [cljs-bean.core :as bean]
             [frontend.handler.file :as file-handler]
             [frontend.handler.notification :as notification]
-            [clojure.edn :as edn]))
+            [clojure.edn :as edn]
+            [frontend.state :as state]))
 
 (defmulti handle identity)
 
@@ -13,6 +14,9 @@
 (defmethod handle :notification [_ data]
   (apply notification/show! (edn/read-string data)))
 
+(defmethod handle :add-repo [_ data]
+  (state/add-repo! {:url (:repo (edn/read-string data))}))
+
 (defmethod handle :default [_ data]
   (prn :debug "Worker data not handled: " data))
 

+ 13 - 9
src/main/frontend/worker/rtc/full_upload_download_graph.cljs

@@ -11,10 +11,9 @@
             [frontend.worker.rtc.op-mem-layer :as op-mem-layer]
             [frontend.worker.rtc.ws :refer [<send!]]
             [logseq.db.frontend.schema :as db-schema]
-
-            ;; TODO:
-            [frontend.persist-db :as persist-db]
-            [frontend.state :as state]))
+            [frontend.worker.state :as state]
+            [promesa.core :as p]
+            [frontend.worker.util :as worker-util]))
 
 (def transit-r (transit/reader :json))
 
@@ -120,11 +119,16 @@
   (go-try
    (let [{:keys [t blocks]} all-blocks
          blocks* (replace-db-id-with-temp-id blocks)
-         blocks-with-page-id (fill-block-fields blocks*)]
-     (<? (p->c (persist-db/<new repo)))
-     (<? (p->c (persist-db/<transact-data repo blocks-with-page-id nil)))
-     (<? (p->c (persist-db/<release-access-handles repo)))
-     (state/add-repo! {:url repo})
+         blocks-with-page-id (fill-block-fields blocks*)
+         ^js sqlite @state/*sqlite
+         work (p/do!
+               (.createOrOpenDB sqlite repo)
+               (.exportDB sqlite repo)
+               (.transact repo blocks-with-page-id nil (state/get-context))
+               (.releaseAccessHandles sqlite repo))]
+     (<? (p->c work))
+
+     (worker-util/post-message :add-repo (pr-str {:repo repo}))
      (op-mem-layer/update-local-tx! repo t))))
 
 (defn <download-graph