refactor: make db transaction sync and add refresh

pull/1686/head
Tienson Qin 2021-04-16 23:14:08 +08:00
parent ba0f6bd734
commit 4571723694
2 changed files with 14 additions and 14 deletions

View File

@ -130,5 +130,6 @@
:block/scheduled :block/scheduled
:block/deadline :block/deadline
:block/repeated? :block/repeated?
:block/properties
} }
) )

View File

@ -470,13 +470,10 @@
:else :else
(not has-children?))] (not has-children?))]
(let [*blocks (atom [current-node]) (let [*blocks (atom [current-node])]
_ (outliner-core/insert-node new-node current-node sibling? {:blocks-atom *blocks (outliner-core/save-node current-node)
:skip-transact? true}) (outliner-core/insert-node new-node current-node sibling? {:blocks-atom *blocks
tx-f (fn [] :skip-transact? false})
(outliner-core/save-node current-node)
(outliner-core/insert-node new-node current-node sibling?))]
(if dummy? (tx-f) (state/add-tx! tx-f))
@*blocks))) @*blocks)))
(defn- block-self-alone-when-insert? (defn- block-self-alone-when-insert?
@ -560,15 +557,17 @@
(wrap-parse-block)) (wrap-parse-block))
blocks (profile blocks (profile
"outliner insert block" "outliner insert block"
(outliner-insert-block! current-block next-block block-self?))] (outliner-insert-block! current-block next-block block-self?))
refresh-fn (fn []
(let [opts {:key :block/insert
:data [current-block next-block]}]
(db/refresh! repo opts)))]
(do (do
(if dummy? (if dummy?
(profile (refresh-fn)
"db refresh" (do
(let [opts {:key :block/insert (profile "update cache " (update-cache-for-block-insert! repo config block blocks))
:data [current-block next-block]}] (state/add-tx! refresh-fn)))
(db/refresh! repo opts)))
(profile "update cache " (update-cache-for-block-insert! repo config block blocks)))
(profile "ok handler" (ok-handler next-block)) (profile "ok handler" (ok-handler next-block))
(state/set-editor-op! nil)))) (state/set-editor-op! nil))))