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

pull/11177/head
Tienson Qin 2024-04-14 08:33:53 +08:00
parent e03b5a2322
commit ebe67390fa
4 changed files with 10 additions and 13 deletions

View File

@ -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)
(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))))
(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]

View File

@ -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)]

View File

@ -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)]]

View File

@ -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)