1
0
Эх сурвалжийг харах

perf: avoid transacting both blocks and properties to UI db

when displayed in table view
Tienson Qin 9 сар өмнө
parent
commit
5305460694

+ 8 - 4
src/main/frontend/components/block.cljs

@@ -3342,7 +3342,8 @@
     (nil? (:level config))
     (assoc :level 0)))
 
-(defn- build-block [config block* {:keys [navigating-block navigated?]}]
+(defn- build-block
+  [config block* {:keys [navigating-block navigated?]}]
   (let [linked-block (:block/link (db/entity (:db/id block*)))
         block (cond
                 (or (and (:custom-query? config)
@@ -3360,7 +3361,7 @@
 
                 :else
                 block*)
-        result (db/sub-block (:db/id block))]
+        result (or (db/sub-block (:db/id block)) block*)]
     (if linked-block
       [block* result]
       [nil result])))
@@ -3690,8 +3691,11 @@
 (rum/defc block-container
   [config block* & {:as opts}]
   (let [[block set-block!] (hooks/use-state
-                            (some-> (:db/id block*) db/entity))]
-    (when-not (:page-title? config)
+                            (or (some-> (:db/id block*) db/entity)
+                                block*))]
+    (when-not (or (:page-title? config)
+                  (:property-block? config)
+                  (:table-view? config))
       (hooks/use-effect!
        (fn []
          (p/do!

+ 4 - 5
src/main/frontend/components/views.cljs

@@ -1158,16 +1158,15 @@
     (when db-id
       (let [block (db/entity db-id)
             [item set-item!] (hooks/use-state block)
-            opts {:children? false
+            opts {:block-only? true
                   :properties properties
                   :skip-transact? true
                   :skip-refresh? true}]
         (hooks/use-effect!
          (fn []
-           (when (and db-id (not block))
-             (p/let [result (db-async/<get-block (state/get-current-repo) db-id opts)]
-               (let [block (:block result)]
-                 (set-item! (or block (some-> (:db/id block) db/entity)))))))
+           (when (and db-id (not (:block.temp/fully-loaded? block)))
+             (p/let [block (db-async/<get-block (state/get-current-repo) db-id opts)]
+               (set-item! block))))
          [db-id])
         (item-render (assoc item :id (:db/id item) :db/id (:db/id item)))))))
 

+ 8 - 1
src/main/frontend/db/async.cljs

@@ -106,6 +106,10 @@
   [graph id-uuid-or-name & {:keys [children? skip-transact? skip-refresh? block-only? _properties]
                             :or {children? true}
                             :as opts}]
+
+  ;; (prn :debug :<get-block id-uuid-or-name)
+  ;; (js/console.trace)
+
   (let [name' (str id-uuid-or-name)
         opts (assoc opts :children? children?)
         cache-key [id-uuid-or-name opts]
@@ -139,7 +143,10 @@
                 {:keys [block children] :as result'} (first result)]
           (state/update-state! :db/async-query-loading (fn [s] (disj s name')))
           (if skip-transact?
-            (reset! *block-cache (cache/miss @*block-cache cache-key result'))
+            (reset! *block-cache (cache/miss @*block-cache cache-key
+                                             (if (or children? block-only?)
+                                               (:block result')
+                                               result')))
             (let [conn (db/get-db graph false)
                   block-and-children (cons block children)
                   affected-keys [[:frontend.worker.react/block (:db/id block)]]]

+ 2 - 1
src/main/frontend/handler/common/developer.cljs

@@ -39,7 +39,8 @@
     (println pull-data)
     (notification/show!
      [:div.ls-wrap-widen
-      [:pre.code pull-data]
+      [:pre.code (str "ID: " (:db/id result) "\n"
+                      pull-data)]
       [:br]
       (ui/button "Copy to clipboard"
                  :on-click #(.writeText js/navigator.clipboard pull-data))]