Parcourir la source

perf: no need to get all the property pairs when asking for only one

Tienson Qin il y a 1 an
Parent
commit
ebe67390fa

+ 5 - 8
deps/db/src/logseq/db/frontend/property.cljs

@@ -265,14 +265,11 @@
   "Get the value of built-in block's property by its db-ident"
   [repo db block db-ident]
   (when db
-    (let [block (or (d/entity db (:db/id block)) block)
-          ;; FIXME: Use db-based-graph? when this fn moves to another ns
-          properties' (if (and (string/starts-with? repo "logseq_db_")
-                               ;; FIXME: Find a way to do this nbb check without affecting frontend
-                               (not (:block/raw-properties block)))
-                        (properties block)
-                        (:block/properties block))]
-      (lookup repo properties' db-ident))))
+    (let [block (or (d/entity db (:db/id block)) block)]
+      ;; FIXME: Use db-based-graph? when this fn moves to another ns
+      (if (string/starts-with? repo "logseq_db_")
+        (get (get-pair-e block db-ident) db-ident)
+        (lookup repo (:block/properties block) db-ident)))))
 
 (defn shape-block?
   [repo db block]

+ 1 - 2
src/main/frontend/components/editor.cljs

@@ -583,8 +583,7 @@
   "Get textarea css class according to it's content"
   [block content format]
   (let [content (if content (str content) "")
-        properties (:block/properties block)
-        heading (pu/lookup properties :logseq.property/heading)
+        heading (pu/get-block-property-value block :logseq.property/heading)
         heading (if (true? heading)
                   (min (inc (:block/level block)) 6)
                   heading)]

+ 3 - 2
src/main/frontend/components/right_sidebar.cljs

@@ -20,7 +20,8 @@
             [medley.core :as medley]
             [reitit.frontend.easy :as rfe]
             [rum.core :as rum]
-            [frontend.db.rtc.debug-ui :as rtc-debug-ui]))
+            [frontend.db.rtc.debug-ui :as rtc-debug-ui]
+            [frontend.handler.property.util :as pu]))
 
 (rum/defc toggle
   []
@@ -98,7 +99,7 @@
           page (db/entity repo lookup)
           page-name (:block/name page)]
       [[:.flex.items-center.page-title
-        (if-let [icon (get-in page [:block/properties :icon])]
+        (if-let [icon (pu/get-block-property-value page :logseq.property/icon)]
           [:.text-md.mr-2 icon]
           (ui/icon (if (= "whiteboard" (:block/type page)) "whiteboard" "page") {:class "text-md mr-2"}))
         [:span.overflow-hidden.text-ellipsis (:block/original-name page)]]

+ 1 - 1
src/main/frontend/db/model.cljs

@@ -367,7 +367,7 @@ independent of format as format specific heading characters are stripped"
 (defn get-block-parents-v2
   [repo block-id]
   (d/pull (conn/get-db repo)
-          '[:db/id :block/collapsed? :block/properties {:block/parent ...}]
+          '[:db/id :block/collapsed? {:block/parent ...}]
           [:block/uuid block-id]))
 
 (def get-block-last-direct-child-id ldb/get-block-last-direct-child-id)