fix: revise whiteboard saving throttle code

pull/6825/head
Peng Xiao 2022-09-20 16:47:05 +08:00
parent b4e6ad4769
commit 2c4798f6dd
4 changed files with 23 additions and 10 deletions

View File

@ -104,7 +104,6 @@
(let [{:keys [pages assets]} (js->clj tldr :keywordize-keys true)
page (first pages)
tx (tldr-page->blocks-tx page-name (assoc page :assets assets))]
(state/set-last-transact-time! (state/get-current-repo) (util/time-ms))
(db-utils/transact! tx)))
(defn get-default-tldr

View File

@ -42,8 +42,10 @@
page-db-id (:db/id page-block)
whiteboard? (:block/whiteboard? page-block)
blocks-count (model/get-page-blocks-count repo page-db-id)]
(if (and (or (> blocks-count 500) whiteboard?)
(not (state/input-idle? repo :diff 3000))) ; long page or whiteboard
(if (or (and (> blocks-count 500)
(not (state/input-idle? repo :diff 3000))) ;; long page
;; when this whiteboard page is just being updated
(and whiteboard? (state/whiteboard-page-idle? repo page-block 3000)))
(async/put! (state/get-file-write-chan) [repo page-db-id])
(let [pull-keys (if whiteboard? whiteboard-blocks-pull-keys-with-persisted-ids '[*])
blocks (model/get-page-blocks-no-cache repo (:block/name page-block) {:pull-keys pull-keys})

View File

@ -34,6 +34,7 @@
(fn [e]
(when (and (or (contains? #{:srs :page-histories} (state/get-modal-id))
(not (state/block-component-editing?)))
(not (and (state/tldraw-idle?)
(not (state/editing?)))))
;; should not enable when in whiteboard mode, but not editing a logseq block
(not (and (state/active-tldraw-app)
(not (state/tldraw-editing-logseq-block?)))))
(f e))))

View File

@ -1400,12 +1400,11 @@ Similar to re-frame subscriptions"
[]
^js js/window.tln)
(defn tldraw-idle?
"return true when tldraw is active and idle. nil when tldraw is
not active."
(defn tldraw-editing-logseq-block?
[]
(when-let [app (active-tldraw-app)]
(.. app -selectedTool (isIn "idle"))))
(and (= 1 (.. app -selectedShapesArray -length))
(= (.. app -editingShape) (.. app -selectedShapesArray (at 0))))))
(defn set-graph-syncing?
[value]
@ -1460,7 +1459,19 @@ Similar to re-frame subscriptions"
(>= (- now last-time) diff)))
;; not in editing mode
;; Is this a good idea to put whiteboard check here?
(not (or (get-edit-input-id) (active-tldraw-app))))))
(not (get-edit-input-id)))))
(defn whiteboard-page-idle?
[repo whiteboard-page & {:keys [diff]
:or {diff 1000}}]
(when repo
(or
(when-let [last-time (:block/updated-at whiteboard-page)]
(let [now (util/time-ms)]
(>= (- now last-time) diff)))
;; not in idle mode
(not (when-let [tldraw-app (active-tldraw-app)]
(.. tldraw-app -selectedTool (isIn "idle")))))))
(defn set-nfs-refreshing!
[value]