浏览代码

fix: file graph import not persisting to disk

Gabriel Horner 1 年之前
父节点
当前提交
f573b8e821

+ 1 - 1
deps/graph-parser/src/logseq/graph_parser.cljs

@@ -268,7 +268,7 @@ Options available:
         result (if skip-db-transact?
         result (if skip-db-transact?
                  tx'
                  tx'
                  (d/transact! conn tx' (select-keys options [:new-graph? :from-disk?])))]
                  (d/transact! conn tx' (select-keys options [:new-graph? :from-disk?])))]
-    {:tx result
+    {:tx-report result
      :ast ast}))
      :ast ast}))
 
 
 (defn filter-files
 (defn filter-files

+ 7 - 3
src/main/frontend/components/imports.cljs

@@ -11,6 +11,7 @@
             [frontend.context.i18n :refer [t]]
             [frontend.context.i18n :refer [t]]
             [frontend.db :as db]
             [frontend.db :as db]
             [frontend.fs :as fs]
             [frontend.fs :as fs]
+            [frontend.persist-db.browser :as db-browser]
             [frontend.handler.db-based.editor :as db-editor-handler]
             [frontend.handler.db-based.editor :as db-editor-handler]
             [frontend.handler.import :as import-handler]
             [frontend.handler.import :as import-handler]
             [frontend.handler.notification :as notification]
             [frontend.handler.notification :as notification]
@@ -161,7 +162,7 @@
 
 
 
 
 (defn- import-from-doc-files!
 (defn- import-from-doc-files!
-  [db-conn doc-files]
+  [db-conn repo doc-files]
   (let [imported-chan (async/promise-chan)]
   (let [imported-chan (async/promise-chan)]
     (try
     (try
       (let [docs-chan (async/to-chan! (medley/indexed doc-files))]
       (let [docs-chan (async/to-chan! (medley/indexed doc-files))]
@@ -178,7 +179,10 @@
                                             {:file/path (.-rpath file)
                                             {:file/path (.-rpath file)
                                              :file/content content}))
                                              :file/content content}))
                                   (p/then (fn [file]
                                   (p/then (fn [file]
-                                            (graph-parser/import-file-to-db-graph db-conn (:file/path file) (:file/content file) {})
+                                            ;; Write to frontend first as writing to worker first is poor ux with slow streaming changes
+                                            (let [{:keys [tx-report]}
+                                                  (graph-parser/import-file-to-db-graph db-conn (:file/path file) (:file/content file) {})]
+                                              (db-browser/transact! @db-browser/*worker repo (:tx-data tx-report) (:tx-meta tx-report)))
                                             file)))))
                                             file)))))
               (recur))
               (recur))
             (async/offer! imported-chan true))))
             (async/offer! imported-chan true))))
@@ -272,7 +276,7 @@
                                     db-conn (db/get-db repo false)]
                                     db-conn (db/get-db repo false)]
                                 (async/<! (p->c (import-config-file! config-file)))
                                 (async/<! (p->c (import-config-file! config-file)))
                                 (async/<! (import-from-asset-files! asset-files))
                                 (async/<! (import-from-asset-files! asset-files))
-                                (async/<! (import-from-doc-files! db-conn doc-files))
+                                (async/<! (import-from-doc-files! db-conn repo doc-files))
                                 (state/set-state! :graph/importing nil)
                                 (state/set-state! :graph/importing nil)
                                 (finished-cb)))))]
                                 (finished-cb)))))]
     (state/set-modal!
     (state/set-modal!

+ 1 - 1
src/main/frontend/persist_db/browser.cljs

@@ -38,7 +38,7 @@
                  (when (seq new-state)
                  (when (seq new-state)
                    (.sync-app-state worker (pr-str new-state)))))))
                    (.sync-app-state worker (pr-str new-state)))))))
 
 
-(defn- transact!
+(defn transact!
   [^js worker repo tx-data tx-meta]
   [^js worker repo tx-data tx-meta]
   (let [tx-meta' (pr-str tx-meta)
   (let [tx-meta' (pr-str tx-meta)
         tx-data' (pr-str tx-data)
         tx-data' (pr-str tx-data)