Skip to content

Commit 3c9dee9

Browse files
committed
fix: invalid data when deleting closed value
fixes logseq/db-test#729
1 parent 99fb075 commit 3c9dee9

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

deps/db/src/logseq/db/common/delete_blocks.cljs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@
6363
retract-reactions-tx (map (fn [reaction] [:db/retractEntity (:db/id reaction)])
6464
reaction-entities)
6565
retracted-tx (build-retracted-tx retracted-blocks)
66-
retract-history-tx (mapcat (fn [e]
67-
(map (fn [history] [:db/retractEntity (:db/id history)])
68-
(:logseq.property.history/_block e))) retracted-blocks)
66+
history-entities (->> retracted-blocks
67+
(mapcat (fn [e]
68+
(concat (:logseq.property.history/_block e)
69+
(:logseq.property.history/_ref-value e))))
70+
(common-util/distinct-by :db/id))
71+
retract-history-tx (map (fn [history] [:db/retractEntity (:db/id history)])
72+
history-entities)
6973
delete-views (->>
7074
(mapcat
7175
(fn [item]

deps/db/test/logseq/db/common/delete_blocks_test.cljs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,26 @@
2424
extra (delete-blocks/update-refs-history @conn retracts {})]
2525
(d/transact! conn (concat retracts extra))
2626
(is (nil? (d/entity @conn (:db/id reaction-entity)))))))
27+
28+
(deftest delete-blocks-removes-history-with-ref-value
29+
(testing "property history entries referencing a deleted block are retracted"
30+
(let [conn (db-test/create-conn-with-blocks
31+
{:pages-and-blocks
32+
[{:page {:block/title "Page"}
33+
:blocks [{:block/title "Target block"}
34+
{:block/title "Choice value"}]}]})
35+
target-block (db-test/find-block-by-content @conn "Target block")
36+
choice-value-block (db-test/find-block-by-content @conn "Choice value")
37+
history-uuid (random-uuid)
38+
now (common-util/time-ms)
39+
_ (d/transact! conn [{:block/uuid history-uuid
40+
:block/created-at now
41+
:block/updated-at now
42+
:logseq.property.history/block (:db/id target-block)
43+
:logseq.property.history/property (:db/id (d/entity @conn :logseq.property/status))
44+
:logseq.property.history/ref-value (:db/id choice-value-block)}])
45+
history-entity (d/entity @conn [:block/uuid history-uuid])
46+
retracts [[:db/retractEntity (:db/id choice-value-block)]]
47+
extra (delete-blocks/update-refs-history @conn retracts {})]
48+
(d/transact! conn (concat retracts extra))
49+
(is (nil? (d/entity @conn (:db/id history-entity)))))))

0 commit comments

Comments
 (0)