Browse Source

fix(regression): slow editing in file graph

The root cause is that logseq tries to save the file each time when
there's a transaction.
Tienson Qin 5 months ago
parent
commit
ed32cfb4c9

+ 9 - 4
src/main/frontend/handler/editor.cljs

@@ -1343,11 +1343,18 @@
    (doseq [[block value] blocks]
      (save-block-if-changed! block value))))
 
+(defonce *auto-save-timeout (atom nil))
+(defn- clear-block-auto-save-timeout!
+  []
+  (when @*auto-save-timeout
+    (js/clearTimeout @*auto-save-timeout)))
+
 (defn save-current-block!
   "skip-properties? if set true, when editing block is likely be properties, skip saving"
   ([]
    (save-current-block! {}))
   ([{:keys [force? skip-properties? current-block] :as opts}]
+   (clear-block-auto-save-timeout!)
    ;; non English input method
    (when-not (or (state/editor-in-composition?)
                  (state/get-editor-action))
@@ -1803,15 +1810,13 @@
             new-value (string/replace value full_text new-full-text)]
         (save-block-aux! block new-value {})))))
 
-(defonce *auto-save-timeout (atom nil))
 (defn edit-box-on-change!
   [e block id]
   (when (= (:db/id block) (:db/id (state/get-edit-block)))
     (let [value (util/evalue e)
           repo (state/get-current-repo)]
       (state/set-edit-content! id value false)
-      (when @*auto-save-timeout
-        (js/clearTimeout @*auto-save-timeout))
+      (clear-block-auto-save-timeout!)
       (block-handler/mark-last-input-time! repo)
       (reset! *auto-save-timeout
               (js/setTimeout
@@ -1821,7 +1826,7 @@
                             (not (and
                                   (config/db-based-graph? repo)
                                   (re-find #"#\S+" value))))
-                 ; don't auto-save for page's properties block
+                   ; don't auto-save for page's properties block
                    (save-current-block! {:skip-properties? true})))
                450)))))
 

+ 1 - 0
src/main/frontend/worker/db_listener.cljs

@@ -16,6 +16,7 @@
 (defn- sync-db-to-main-thread
   "Return tx-report"
   [repo conn {:keys [tx-meta] :as tx-report}]
+  (when repo (worker-state/set-db-latest-tx-time! repo))
   (let [{:keys [from-disk?]} tx-meta
         result (worker-pipeline/invoke-hooks repo conn tx-report (worker-state/get-context))
         tx-report' (:tx-report result)]

+ 5 - 3
src/main/frontend/worker/file.cljs

@@ -147,7 +147,7 @@
 
 (defn do-write-file!
   [repo conn page-db-id outliner-op context request-id]
-  (let [page-block (d/pull @conn '[*] page-db-id)
+  (let [page-block (d/entity @conn page-db-id)
         page-db-id (:db/id page-block)
         whiteboard? (file-entity-util/whiteboard? page-block)
         blocks-count (ldb/get-page-blocks-count @conn page-db-id)
@@ -157,8 +157,10 @@
       (if (and (or (> blocks-count 500) whiteboard?)
                (not (worker-state/tx-idle? repo {:diff 3000})))
         (async/put! file-writes-chan [repo page-db-id outliner-op (tc/to-long (t/now)) request-id])
-        (let [pull-keys (if whiteboard? whiteboard-blocks-pull-keys-with-persisted-ids '[*])
-              blocks (ldb/get-page-blocks @conn (:db/id page-block) {:pull-keys pull-keys})
+        (let [blocks (if whiteboard?
+                       (ldb/get-page-blocks @conn (:db/id page-block)
+                                            {:pull-keys whiteboard-blocks-pull-keys-with-persisted-ids})
+                       (:block/_page page-block))
               blocks (if whiteboard? (map cleanup-whiteboard-block blocks) blocks)]
           (if (and (= 1 (count blocks))
                    (string/blank? (:block/title (first blocks)))