mirror of
https://github.com/logseq/logseq.git
synced 2026-05-02 18:06:32 +00:00
Improve long page editing performance (#3855)
* Remove expensive parsing when saving files * Add limit to page blocks query * Don't collapse block's body to make it compatible with other tools * Alert if there're unsaved changes when switching graphs * DB schema migration for :block/collapsed? from it's property Co-authored-by: Andelf <andelf@gmail.com>
This commit is contained in:
@@ -15,8 +15,7 @@
|
||||
[lambdaisland.glogi :as log]
|
||||
[promesa.core :as p]
|
||||
[rum.core :as rum]
|
||||
[frontend.mobile.util :as mobile-util]
|
||||
[cljs.cache :as cache]))
|
||||
[frontend.mobile.util :as mobile-util]))
|
||||
|
||||
(defonce state
|
||||
(let [document-mode? (or (storage/get :document/mode?) false)
|
||||
@@ -207,33 +206,24 @@
|
||||
|
||||
:srs/mode? false
|
||||
|
||||
:srs/cards-due-count nil})))
|
||||
:srs/cards-due-count nil
|
||||
})))
|
||||
|
||||
;; block uuid -> {content(String) -> ast}
|
||||
(def blocks-ast-cache (atom (cache/lru-cache-factory {} :threshold 5000)))
|
||||
(def blocks-ast-cache (atom {}))
|
||||
(defn add-block-ast-cache!
|
||||
[block-uuid content ast]
|
||||
(when (and block-uuid content ast)
|
||||
(let [k block-uuid
|
||||
add-cache! (fn []
|
||||
(reset! blocks-ast-cache (cache/evict @blocks-ast-cache block-uuid))
|
||||
(reset! blocks-ast-cache (cache/miss @blocks-ast-cache k {content ast})))]
|
||||
(if (cache/has? @blocks-ast-cache k)
|
||||
(let [m (cache/lookup @blocks-ast-cache k)]
|
||||
(if (and (map? m) (get m content))
|
||||
(reset! blocks-ast-cache (cache/hit @blocks-ast-cache k))
|
||||
(add-cache!)))
|
||||
(add-cache!)))))
|
||||
(let [new-value (assoc-in @blocks-ast-cache [block-uuid content] ast)
|
||||
new-value (if (> (count new-value) 10000)
|
||||
(into {} (take 5000 new-value))
|
||||
new-value)]
|
||||
(reset! blocks-ast-cache new-value))))
|
||||
|
||||
(defn get-block-ast
|
||||
[block-uuid content]
|
||||
(when (and block-uuid content)
|
||||
(let [k block-uuid]
|
||||
(when (cache/has? @blocks-ast-cache k)
|
||||
(let [m (cache/lookup @blocks-ast-cache k)]
|
||||
(when-let [result (and (map? m) (get m content))]
|
||||
(reset! blocks-ast-cache (cache/hit @blocks-ast-cache k))
|
||||
result))))))
|
||||
(get-in @blocks-ast-cache [block-uuid content])))
|
||||
|
||||
(defn sub
|
||||
[ks]
|
||||
|
||||
Reference in New Issue
Block a user