Browse Source

fix: wait until db transacted and then parsing the next 100 files

Related to LOG-3057
Tienson Qin 1 year ago
parent
commit
49596151bb

+ 2 - 5
src/main/frontend/db/react.cljs

@@ -191,14 +191,11 @@
      (doseq [k all-keys]
      (doseq [k all-keys]
        (when-let [cache (get state k)]
        (when-let [cache (get state k)]
          (let [{:keys [query query-fn]} cache
          (let [{:keys [query query-fn]} cache
-               custom? (= :custom (first k))
-               {:keys [custom-query?]} (state/edit-in-query-or-refs-component)]
+               custom? (= :custom (first k))]
            (when (or query query-fn)
            (when (or query query-fn)
              (try
              (try
                (let [f #(execute-query! repo-url db (vec (cons repo-url k)) cache)]
                (let [f #(execute-query! repo-url db (vec (cons repo-url k)) cache)]
-                       ;; Detects whether user is editing in a custom query, if so, execute the query immediately
-                 (if (and custom? (not custom-query?))
-                   (async/put! (state/get-reactive-custom-queries-chan) [f query])
+                 (when-not custom?
                    (f)))
                    (f)))
                (catch :default e
                (catch :default e
                  (js/console.error e)
                  (js/console.error e)

+ 1 - 0
src/main/frontend/handler/file_based/nfs.cljs

@@ -156,6 +156,7 @@
                                                                              {:new-graph?   true
                                                                              {:new-graph?   true
                                                                               :empty-graph? (nil? (seq markup-files))
                                                                               :empty-graph? (nil? (seq markup-files))
                                                                               :file-objs    files})
                                                                               :file-objs    files})
+                                     (state/set-parsing-state! {:graph-loading? false})
                                      (state/add-repo! {:url repo :nfs? true})
                                      (state/add-repo! {:url repo :nfs? true})
                                      (persist-db/<export-db repo {})
                                      (persist-db/<export-db repo {})
                                      (state/set-loading-files! repo false)
                                      (state/set-loading-files! repo false)

+ 10 - 9
src/main/frontend/handler/file_based/repo.cljs

@@ -21,7 +21,8 @@
             [logseq.common.config :as common-config]
             [logseq.common.config :as common-config]
             [clojure.core.async :as async]
             [clojure.core.async :as async]
             [medley.core :as medley]
             [medley.core :as medley]
-            [logseq.common.path :as path]))
+            [logseq.common.path :as path]
+            [clojure.core.async.interop :refer [p->c]]))
 
 
 (defn- create-contents-file
 (defn- create-contents-file
   [repo-url]
   [repo-url]
@@ -238,14 +239,15 @@
                   _ (when (and page-name (not page-exists?))
                   _ (when (and page-name (not page-exists?))
                       (swap! *page-names conj page-name)
                       (swap! *page-names conj page-name)
                       (swap! *page-name->path assoc page-name (:file/path file)))
                       (swap! *page-name->path assoc page-name (:file/path file)))
-                  tx' (if (or whiteboard? (zero? (rem (inc idx) 100)))
-                        (do (db/transact! repo-url tx' {:from-disk? true})
-                            [])
+                  tx' (if (zero? (rem (inc idx) 100))
+                        (do
+                          (async/<! (p->c (db/transact! repo-url tx' {:from-disk? true})))
+                          [])
                         tx')]
                         tx')]
               (recur tx')))
               (recur tx')))
-          (do
-            (when (seq tx) (db/transact! repo-url tx {:from-disk? true}))
-            (after-parse repo-url re-render? re-render-opts opts graph-added-chan)))))
+          (p/do!
+           (when (seq tx) (db/transact! repo-url tx {:from-disk? true}))
+           (after-parse repo-url re-render? re-render-opts opts graph-added-chan)))))
     graph-added-chan))
     graph-added-chan))
 
 
 (defn- parse-files-and-create-default-files!
 (defn- parse-files-and-create-default-files!
@@ -276,8 +278,7 @@
 
 
     ;; Load to db even it's empty, (will create default files)
     ;; Load to db even it's empty, (will create default files)
     (parse-files-and-load-to-db! repo-url file-objs {:new-graph? new-graph?
     (parse-files-and-load-to-db! repo-url file-objs {:new-graph? new-graph?
-                                                     :empty-graph? empty-graph?})
-    (state/set-parsing-state! {:graph-loading? false})))
+                                                     :empty-graph? empty-graph?})))
 
 
 (defn load-repo-to-db!
 (defn load-repo-to-db!
   [repo-url {:keys [diffs file-objs refresh? new-graph? empty-graph?]}]
   [repo-url {:keys [diffs file-objs refresh? new-graph? empty-graph?]}]

+ 8 - 8
src/main/frontend/search/browser.cljs

@@ -31,14 +31,14 @@
               file-based? (config/local-file-based-graph? repo)
               file-based? (config/local-file-based-graph? repo)
               _ (protocol/truncate-blocks! this)
               _ (protocol/truncate-blocks! this)
               result (.search-build-blocks-indice sqlite repo)
               result (.search-build-blocks-indice sqlite repo)
-              blocks (cond->> (bean/->clj result)
-                       file-based?
-                       ;; remove built-in properties from content
-                       (map #(update % :content
-                                     (fn [content]
-                                       (property-util/remove-built-in-properties (get % :format :markdown) content))))
-                       true
-                       bean/->js)
+              blocks (if file-based?
+                       (->> (bean/->clj result)
+                            ;; remove built-in properties from content
+                            (map #(update % :content
+                                          (fn [content]
+                                            (property-util/remove-built-in-properties (get % :format :markdown) content))))
+                            bean/->js)
+                       result)
               _ (when (seq blocks)
               _ (when (seq blocks)
                   (.search-upsert-blocks sqlite repo blocks))])
                   (.search-upsert-blocks sqlite repo blocks))])
       (p/resolved nil)))
       (p/resolved nil)))