fix: slow re-index for large graphs with page-metadata.edn

related to #5547
pull/5686/head
Tienson Qin 2022-06-13 17:43:24 +08:00
parent b3d01a869b
commit 156b152129
4 changed files with 18 additions and 12 deletions

View File

@ -1450,11 +1450,13 @@
(mapv (fn [page] [:db.fn/retractEntity [:block/name page]]) (map util/page-name-sanity-lc pages)))))
(defn set-file-content!
[repo path content]
(when (and repo path)
(let [tx-data {:file/path path
:file/content content}]
(db-utils/transact! repo [tx-data] {:skip-refresh? true}))))
([repo path content]
(set-file-content! repo path content {}))
([repo path content opts]
(when (and repo path)
(let [tx-data {:file/path path
:file/content content}]
(db-utils/transact! repo [tx-data] (merge opts {:skip-refresh? true}))))))
(defn get-pre-block
[repo page-id]

View File

@ -155,16 +155,18 @@
#(p/resolved nil)
#(fs/write-file! repo (config/get-repo-dir repo) path content
(assoc (when original-content {:old-content original-content})
:skip-compare? skip-compare?)))]
:skip-compare? skip-compare?)))
opts {:new-graph? new-graph?
:from-disk? from-disk?}]
(if reset?
(do
(when-let [page-id (db/get-file-page-id path)]
(db/transact! repo
[[:db/retract page-id :block/alias]
[:db/retract page-id :block/tags]]))
(reset-file! repo path content {:new-graph? new-graph?
:from-disk? from-disk?}))
(db/set-file-content! repo path content))
[:db/retract page-id :block/tags]]
opts))
(reset-file! repo path content opts))
(db/set-file-content! repo path content opts))
(util/p-handle (write-file!)
(fn [_]
(when (= path (config/get-config-path repo))

View File

@ -268,7 +268,8 @@
(repo-handler/load-repo-to-db! repo
{:diffs diffs
:nfs-files modified-files
:refresh? (not re-index?)}))
:refresh? (not re-index?)
:new-graph? re-index?}))
(when (and (util/electron?) (not re-index?))
(db/transact! repo new-files))))))))

View File

@ -12,7 +12,8 @@
(when (and (not (:from-disk? (:tx-meta tx-report)))
(not (:new-graph? (:tx-meta tx-report))))
(let [{:keys [pages blocks]} (ds-report/get-blocks-and-pages tx-report)]
(doseq [p (seq pages)] (updated-page-hook tx-report p))
(doseq [p (seq pages)]
(updated-page-hook tx-report p))
(when (and state/lsp-enabled? (seq blocks))
(state/pub-event! [:plugin/hook-db-tx
{:blocks blocks