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:
Tienson Qin
2022-01-18 10:37:31 +08:00
committed by GitHub
parent 6a151937d7
commit 6aba8c3241
28 changed files with 429 additions and 348 deletions

View File

@@ -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]