From 49596151bb4f10079d2be68ad3250e90dddc5c8b Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 4 Mar 2024 16:26:18 +0800 Subject: [PATCH] fix: wait until db transacted and then parsing the next 100 files Related to LOG-3057 --- src/main/frontend/db/react.cljs | 7 ++----- src/main/frontend/handler/file_based/nfs.cljs | 1 + .../frontend/handler/file_based/repo.cljs | 19 ++++++++++--------- src/main/frontend/search/browser.cljs | 16 ++++++++-------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/main/frontend/db/react.cljs b/src/main/frontend/db/react.cljs index ff3b0b42a..7472a2eee 100644 --- a/src/main/frontend/db/react.cljs +++ b/src/main/frontend/db/react.cljs @@ -191,14 +191,11 @@ (doseq [k all-keys] (when-let [cache (get state k)] (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) (try (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))) (catch :default e (js/console.error e) diff --git a/src/main/frontend/handler/file_based/nfs.cljs b/src/main/frontend/handler/file_based/nfs.cljs index c2ec37da4..8d32ed48d 100644 --- a/src/main/frontend/handler/file_based/nfs.cljs +++ b/src/main/frontend/handler/file_based/nfs.cljs @@ -156,6 +156,7 @@ {:new-graph? true :empty-graph? (nil? (seq markup-files)) :file-objs files}) + (state/set-parsing-state! {:graph-loading? false}) (state/add-repo! {:url repo :nfs? true}) (persist-db/c]])) (defn- create-contents-file [repo-url] @@ -238,14 +239,15 @@ _ (when (and page-name (not page-exists?)) (swap! *page-names conj page-name) (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/c (db/transact! repo-url tx' {:from-disk? true}))) + []) 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)) (defn- parse-files-and-create-default-files! @@ -276,8 +278,7 @@ ;; 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? - :empty-graph? empty-graph?}) - (state/set-parsing-state! {:graph-loading? false}))) + :empty-graph? empty-graph?}))) (defn load-repo-to-db! [repo-url {:keys [diffs file-objs refresh? new-graph? empty-graph?]}] diff --git a/src/main/frontend/search/browser.cljs b/src/main/frontend/search/browser.cljs index d4b0b4a01..e9bd1ea14 100644 --- a/src/main/frontend/search/browser.cljs +++ b/src/main/frontend/search/browser.cljs @@ -31,14 +31,14 @@ file-based? (config/local-file-based-graph? repo) _ (protocol/truncate-blocks! this) 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) (.search-upsert-blocks sqlite repo blocks))]) (p/resolved nil)))