mirror of https://github.com/logseq/logseq
fix: lazy load properoty value blocks
parent
236a28764b
commit
09f65cf842
|
@ -71,6 +71,23 @@
|
|||
[b]
|
||||
(assoc b :block.temp/fully-loaded? true))
|
||||
|
||||
(defn- property-with-values
|
||||
[db block]
|
||||
(let [pairs (d/pull-many db '[*] (map :db/id (:block/raw-properties block)))]
|
||||
(mapcat
|
||||
(fn [pair]
|
||||
(let [property (d/entity db (:db/id (:property/pair-property pair)))
|
||||
property-values (get pair (:db/ident property))
|
||||
values (if (set? property-values) property-values #{property-values})
|
||||
value-ids (when (every? map? values)
|
||||
(map :db/id values))
|
||||
value-blocks (when (seq value-ids) (d/pull-many db '[*] value-ids))
|
||||
page (when (seq values)
|
||||
(when-let [page-id (:db/id (:block/page (d/entity db (:db/id (first values)))))]
|
||||
(d/pull db '[*] page-id)))]
|
||||
(concat [page] value-blocks [pair])))
|
||||
pairs)))
|
||||
|
||||
(defn get-block-and-children
|
||||
[db id children?]
|
||||
(let [block (d/entity db (if (uuid? id)
|
||||
|
@ -89,7 +106,7 @@
|
|||
(let [e (d/entity db (:db/id block))]
|
||||
(conj
|
||||
(if (seq (:block/raw-properties e))
|
||||
(vec (d/pull-many db '[*] (map :db/id (:block/raw-properties e))))
|
||||
(vec (property-with-values db e))
|
||||
[])
|
||||
block))))))))]
|
||||
(when block
|
||||
|
@ -101,7 +118,7 @@
|
|||
(cond->
|
||||
{:block block'}
|
||||
(seq (:block/raw-properties block))
|
||||
(assoc :property-pairs (d/pull-many db '[*] (map :db/id (:block/raw-properties block))))
|
||||
(assoc :property-pairs (property-with-values db block))
|
||||
children?
|
||||
(assoc :children (get-children (:block/_parent block)))))
|
||||
(cond->
|
||||
|
@ -109,7 +126,7 @@
|
|||
(with-tags db)
|
||||
mark-block-fully-loaded)}
|
||||
(seq (:block/raw-properties block))
|
||||
(assoc :property-pairs (d/pull-many db '[*] (map :db/id (:block/raw-properties block))))
|
||||
(assoc :property-pairs (property-with-values db block))
|
||||
children?
|
||||
(assoc :children
|
||||
(if (contains? (:block/type block) "whiteboard")
|
||||
|
|
|
@ -478,7 +478,7 @@
|
|||
(rum/defcs property-block-value < rum/reactive
|
||||
(rum/local nil ::template-instance)
|
||||
{:init (fn [state]
|
||||
(let [block-id (first (:rum/args state))]
|
||||
(let [block-id (:block/uuid (first (:rum/args state)))]
|
||||
(db-async/<get-block (state/get-current-repo) block-id :children? true))
|
||||
state)}
|
||||
[state value block property block-cp editor-box opts page-cp editor-id]
|
||||
|
@ -491,7 +491,7 @@
|
|||
(let [class? (contains? (:block/type v-block) "class")
|
||||
invalid-warning [:div.warning.text-sm
|
||||
"Invalid block value, please delete the current property."]]
|
||||
(if v-block
|
||||
(when v-block
|
||||
(cond
|
||||
(:block/page v-block)
|
||||
(property-normal-block-value v-block block-cp editor-box)
|
||||
|
@ -511,8 +511,7 @@
|
|||
:tag? class?} v-block)
|
||||
(:db/id v-block))
|
||||
:else
|
||||
invalid-warning)
|
||||
invalid-warning))
|
||||
invalid-warning)))
|
||||
(property-empty-value))))))
|
||||
|
||||
(rum/defc closed-value-item < rum/reactive
|
||||
|
|
|
@ -326,11 +326,10 @@
|
|||
(ldb/write-transit-str result))))
|
||||
|
||||
(get-block-and-children
|
||||
[_this repo id-str children?]
|
||||
(when (common-util/uuid-string? id-str)
|
||||
(when-let [conn (worker-state/get-datascript-conn repo)]
|
||||
(let [id (uuid id-str)]
|
||||
(ldb/write-transit-str (sqlite-common-db/get-block-and-children @conn id children?))))))
|
||||
[_this repo id children?]
|
||||
(when-let [conn (worker-state/get-datascript-conn repo)]
|
||||
(let [id (if (and (string? id) (common-util/uuid-string? id)) (uuid id) id)]
|
||||
(ldb/write-transit-str (sqlite-common-db/get-block-and-children @conn id children?)))))
|
||||
|
||||
(get-block-refs
|
||||
[_this repo id]
|
||||
|
|
Loading…
Reference in New Issue