mirror of https://github.com/logseq/logseq
perf: delay writes for long page
parent
ca7b86f082
commit
5aa0db2f21
|
@ -25,14 +25,18 @@
|
|||
[repo page-db-id]
|
||||
(let [page-block (db/pull repo '[*] page-db-id)
|
||||
page-db-id (:db/id page-block)
|
||||
blocks (model/get-page-blocks-no-cache repo (:block/name page-block))]
|
||||
(when-not (and (= 1 (count blocks))
|
||||
(string/blank? (:block/content (first blocks)))
|
||||
(nil? (:block/file page-block)))
|
||||
(let [tree (tree/blocks->vec-tree repo blocks (:block/name page-block))]
|
||||
(if page-block
|
||||
(file/save-tree page-block tree)
|
||||
(js/console.error (str "can't find page id: " page-db-id)))))))
|
||||
blocks-count (model/get-page-blocks-count repo page-db-id)]
|
||||
(if (and (> blocks-count 500)
|
||||
(not (state/input-idle? repo :diff 3000))) ; long page
|
||||
(async/put! write-chan [repo page-db-id])
|
||||
(let [blocks (model/get-page-blocks-no-cache repo (:block/name page-block))]
|
||||
(when-not (and (= 1 (count blocks))
|
||||
(string/blank? (:block/content (first blocks)))
|
||||
(nil? (:block/file page-block)))
|
||||
(let [tree (tree/blocks->vec-tree repo blocks (:block/name page-block))]
|
||||
(if page-block
|
||||
(file/save-tree page-block tree)
|
||||
(js/console.error (str "can't find page id: " page-db-id)))))))))
|
||||
|
||||
(defn write-files!
|
||||
[pages]
|
||||
|
|
|
@ -23,7 +23,10 @@
|
|||
(defn compute-block-path-refs
|
||||
[tx-meta blocks]
|
||||
(let [repo (state/get-current-repo)
|
||||
blocks (remove :block/name blocks)]
|
||||
blocks (remove :block/name blocks)
|
||||
blocks (if (= (:outliner-op tx-meta) :insert-blocks)
|
||||
(butlast blocks)
|
||||
blocks)]
|
||||
(when (:outliner-op tx-meta)
|
||||
(when (react/path-refs-need-recalculated? tx-meta)
|
||||
(let [*computed-ids (atom #{})]
|
||||
|
@ -61,7 +64,9 @@
|
|||
(not (:compute-new-refs? tx-meta)))
|
||||
(let [{:keys [pages blocks]} (ds-report/get-blocks-and-pages tx-report)
|
||||
repo (state/get-current-repo)
|
||||
refs-tx (set (compute-block-path-refs (:tx-meta tx-report) blocks))
|
||||
refs-tx (util/profile
|
||||
"Compute path refs: "
|
||||
(set (compute-block-path-refs (:tx-meta tx-report) blocks)))
|
||||
truncate-refs-tx (map (fn [m] [:db/retract (:db/id m) :block/path-refs]) refs-tx)
|
||||
tx (util/concat-without-nil truncate-refs-tx refs-tx)
|
||||
tx-report' (if (seq tx)
|
||||
|
|
Loading…
Reference in New Issue