Przeglądaj źródła

fix: rtc downloaded graph not persisted

Tienson Qin 1 rok temu
rodzic
commit
39e59109ed

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

@@ -131,7 +131,7 @@
     (when-not (= repo r)
       (close-db-aux! r db search))))
 
-(defn- close-db!
+(defn close-db!
   [repo]
   (let [{:keys [db search]} (@*sqlite-conns repo)]
     (close-db-aux! repo db search)))
@@ -258,8 +258,10 @@
      (bean/->js dbs)))
 
   (createOrOpenDB
-   [_this repo]
-   (p/let [_ (close-other-dbs! repo)]
+   [_this repo & {:keys [close-other-db?]
+                  :or {close-other-db? true}}]
+   (p/let [_ (when close-other-db?
+               (close-other-dbs! repo))]
      (create-or-open-db! repo)))
 
   (getMaxTx
@@ -292,7 +294,8 @@
              tx-meta' (if (:new-graph? tx-meta)
                         tx-meta
                         (cond-> tx-meta
-                          (not (:whiteboard/transact? tx-meta)) ; delay writes to the disk
+                          (and (not (:whiteboard/transact? tx-meta))
+                               (not (:rtc-download-graph? tx-meta))) ; delay writes to the disk
                           (assoc :skip-store? true)
 
                           true
@@ -317,6 +320,10 @@
      (->> (sqlite-common-db/get-initial-data @conn)
           dt/write-transit-str)))
 
+  (closeDB
+   [_this repo]
+   (close-db! repo))
+
   (unsafeUnlinkDB
    [_this repo]
    (p/let [pool (<get-opfs-pool repo)

+ 3 - 3
src/main/frontend/worker/rtc/full_upload_download_graph.cljs

@@ -122,10 +122,10 @@
          blocks-with-page-id (fill-block-fields blocks*)
          ^js worker-obj (:worker/object @worker-state/*state)
          work (p/do!
-               (.createOrOpenDB worker-obj repo)
+               (.createOrOpenDB worker-obj repo {:close-other-db? false})
                (.exportDB worker-obj repo)
-               (.transact worker-obj repo blocks-with-page-id nil (worker-state/get-context))
-               (.releaseAccessHandles worker-obj repo))]
+               (.transact worker-obj repo blocks-with-page-id {:rtc-download-graph? true} (worker-state/get-context))
+               (.closeDB worker-obj repo))]
      (<? (p->c work))
 
      (worker-util/post-message :add-repo (pr-str {:repo repo}))