Browse Source

fix: batch tx

Tienson Qin 2 years ago
parent
commit
8533a974f1
2 changed files with 27 additions and 37 deletions
  1. 5 1
      src/main/frontend/db_worker.cljs
  2. 22 36
      src/main/frontend/handler/editor.cljs

+ 5 - 1
src/main/frontend/db_worker.cljs

@@ -280,9 +280,13 @@
                             (dissoc :insert-blocks?)))]
          (when-not (and (:create-today-journal? tx-meta)
                         (:today-journal-name tx-meta)
+                        (seq tx-data)
                         (d/entity @conn [:block/name (:today-journal-name tx-meta)])) ; today journal created already
+
+           ;; (prn :debug :transact :tx-data tx-data :tx-meta tx-meta')
+
            (worker-util/profile "Worker db transact"
-             (ldb/transact! conn tx-data tx-meta')))
+                                (ldb/transact! conn tx-data tx-meta')))
          nil)
        (catch :default e
          (prn :debug :error)

+ 22 - 36
src/main/frontend/handler/editor.cljs

@@ -270,42 +270,28 @@
                       (assoc :block/uuid (:block/uuid block)))
            opts' (assoc opts :outliner-op :save-block)
            original-block (db/entity (:db/id block))
-           original-props (:block/properties original-block)]
-       (p/let [{:keys [tx-data] :as result}
-               (ui-outliner-tx/transact!
-                opts'
-                (outliner-save-block! block')
-                ;; page properties changed
-                (when-let [page-name (and (:block/pre-block? block')
-                                          (not= original-props (:block/properties block'))
-                                          (some-> (:block/page block') :db/id (db-utils/pull) :block/name))]
-                  (state/set-page-properties-changed! page-name)))
-               [original linked] (when-not (:insert-block? opts)
-                                   (let [original-block (some (fn [m] (and (map? m) (:block/link m) m)) tx-data)
-                                         link (:block/link original-block)
-                                         link' (if (and (map? link) (:db/id link))
-                                                 (db/entity (:db/id link))
-                                                 (db/entity link))]
-                                     [original-block link']))]
-
-         ;; FIXME move this to pipeline
-         ;; Block has been tagged, so we need to edit the linked page now
-         (when (and linked
-                    (= (:db/id (state/get-edit-block)) (:db/id original)))
-           (edit-block! linked :max nil {}))
-
-         ;; file based graph only
-         ;; sanitized page name changed
-         (when-let [title (get-in block' [:block/properties :title])]
-           (if (string? title)
-             (when-let [old-page-name (:block/name (db/entity (:db/id (:block/page block'))))]
-               (when (and (:block/pre-block? block')
-                          (not (string/blank? title))
-                          (not= (util/page-name-sanity-lc title) old-page-name))
-                 (state/pub-event! [:page/title-property-changed old-page-name title true])))
-             (js/console.error (str "Title is not a string: " title))))
-
-         result)))))
+           original-props (:block/properties original-block)
+           result (ui-outliner-tx/transact!
+                   opts'
+                   (outliner-save-block! block')
+                   ;; page properties changed
+                   (when-let [page-name (and (:block/pre-block? block')
+                                             (not= original-props (:block/properties block'))
+                                             (some-> (:block/page block') :db/id (db-utils/pull) :block/name))]
+                     (state/set-page-properties-changed! page-name)))]
+
+       ;; file based graph only
+       ;; sanitized page name changed
+       (when-let [title (get-in block' [:block/properties :title])]
+         (if (string? title)
+           (when-let [old-page-name (:block/name (db/entity (:db/id (:block/page block'))))]
+             (when (and (:block/pre-block? block')
+                        (not (string/blank? title))
+                        (not= (util/page-name-sanity-lc title) old-page-name))
+               (state/pub-event! [:page/title-property-changed old-page-name title true])))
+           (js/console.error (str "Title is not a string: " title))))
+
+       result))))
 
 ;; id: block dom id, "ls-block-counter-uuid"
 (defn- another-block-with-same-id-exists?