Skip to content

Commit 1effbdf

Browse files
fix: referenced property value blocks not exported
with their uuid. Possibly affecting logseq/db-test#636
1 parent 69f0df2 commit 1effbdf

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

deps/db/src/logseq/db/sqlite/export.cljs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@
5555
[:build/page {:build/journal (:block/journal-day pvalue)}]))
5656

5757
(defn- build-pvalue-entity-default [db ent-properties pvalue
58-
{:keys [include-uuid-fn]
59-
:or {include-uuid-fn (constantly false)}
58+
{:keys [content-ref-uuids]
59+
:or {content-ref-uuids #{}}
6060
:as options}]
61-
(if (or (seq ent-properties) (seq (:block/tags pvalue)))
61+
(if (or (seq ent-properties) (seq (:block/tags pvalue)) (contains? content-ref-uuids (:block/uuid pvalue)))
6262
(cond-> {:build/property-value :block
6363
:block/title (or (block-title pvalue)
6464
(:logseq.property/value pvalue))}
@@ -75,7 +75,7 @@
7575
[k v]))))
7676
(into {})))
7777

78-
(include-uuid-fn (:block/uuid pvalue))
78+
(contains? content-ref-uuids (:block/uuid pvalue))
7979
(assoc :block/uuid (:block/uuid pvalue) :build/keep-uuid? true)
8080

8181
(:include-timestamps? options)
@@ -95,10 +95,10 @@
9595
(if-let [build-page (and (not property-value-uuids?) (build-pvalue-entity-for-build-page pvalue))]
9696
build-page
9797
(if (contains? #{:node :date} (:logseq.property/type property-ent))
98-
;; Idents take precedence over uuid because they are keep data graph-agnostic
98+
;; Idents take precedence over uuid because they keep data graph-agnostic
9999
(if (:db/ident pvalue)
100100
(:db/ident pvalue)
101-
;; Use metadata distinguish from block references that don't exist like closed values
101+
;; Use metadata to distinguish from block references that don't exist like closed values
102102
^::existing-property-value? [:block/uuid (:block/uuid pvalue)])
103103
(or (:db/ident pvalue)
104104
(let [ent-properties* (->> (apply dissoc (db-property/properties pvalue)
@@ -488,12 +488,13 @@
488488

489489
(defn- remove-uuid-if-not-ref-given-uuids
490490
[ref-uuids m]
491-
(if (contains? ref-uuids (:block/uuid m))
492-
m
493-
(dissoc m :block/uuid :build/keep-uuid?)))
491+
(cond-> m
492+
(not (contains? ref-uuids (:block/uuid m)))
493+
(dissoc :block/uuid :build/keep-uuid?)))
494494

495495
(defn- build-page-export*
496-
"When given the :handle-block-uuids option, handle references between blocks"
496+
"When given the :handle-block-uuids option, handle uuid references between
497+
blocks including property value blocks"
497498
[db eid page-blocks* {:keys [handle-block-uuids?] :as options}]
498499
(let [page-entity (d/entity db eid)
499500
page-blocks (->> page-blocks*
@@ -542,6 +543,7 @@
542543
{:keys [content-ref-ents] :as content-ref-export} (build-content-ref-export db page-blocks*)
543544
{:keys [pvalue-uuids] :as page-export*}
544545
(build-page-export* db eid page-blocks* {:include-uuid-fn (:content-ref-uuids content-ref-export)
546+
:content-ref-uuids (:content-ref-uuids content-ref-export)
545547
:handle-block-uuids? true
546548
:include-alias? true})
547549
page-entity (d/entity db eid)
@@ -784,7 +786,7 @@
784786
ontology-export (build-graph-ontology-export db ontology-options)
785787
ontology-pvalue-uuids (set (concat (mapcat get-pvalue-uuids (vals (:properties ontology-export)))
786788
(mapcat get-pvalue-uuids (vals (:classes ontology-export)))))
787-
pages-export (build-graph-pages-export db ontology-export options)
789+
pages-export (build-graph-pages-export db ontology-export (assoc options :content-ref-uuids content-ref-uuids))
788790
graph-export* (-> (merge ontology-export pages-export) (dissoc :pvalue-uuids))
789791
graph-export (if (seq (:exclude-namespaces options))
790792
(assoc graph-export* ::auto-include-namespaces (:exclude-namespaces options))

deps/db/test/logseq/db/sqlite/export_test.cljs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,13 @@
304304
{:block/title "block with a pvalue that has a :block/uuid"
305305
:build/properties {:user.property/p2 {:build/property-value :block
306306
:block/title "property value block"
307-
:build/tags [:user.class/C2]
308307
:block/uuid pvalue-block-uuid
309-
:build/keep-uuid? true}}}]}
308+
:build/keep-uuid? true}}}
309+
;; Not a ref case but needed to assert this somewhere
310+
{:block/title "block with a pvalue that has :build/tags"
311+
:build/properties {:user.property/p2 {:build/property-value :block
312+
:block/title "property value block2"
313+
:build/tags [:user.class/C2]}}}]}
310314
{:page {:block/title "page with block ref"}
311315
:blocks [{:block/title "hi" :block/uuid block-uuid :build/keep-uuid? true
312316
:build/properties {:user.property/p1 [:block/uuid block-object-uuid]}}]}

0 commit comments

Comments
 (0)