fix: invalid data when deleting closed value

fixes https://github.com/logseq/db-test/issues/729
This commit is contained in:
Tienson Qin
2026-02-24 22:39:15 +08:00
parent 99fb07586e
commit 3c9dee98da
2 changed files with 30 additions and 3 deletions

View File

@@ -63,9 +63,13 @@
retract-reactions-tx (map (fn [reaction] [:db/retractEntity (:db/id reaction)])
reaction-entities)
retracted-tx (build-retracted-tx retracted-blocks)
retract-history-tx (mapcat (fn [e]
(map (fn [history] [:db/retractEntity (:db/id history)])
(:logseq.property.history/_block e))) retracted-blocks)
history-entities (->> retracted-blocks
(mapcat (fn [e]
(concat (:logseq.property.history/_block e)
(:logseq.property.history/_ref-value e))))
(common-util/distinct-by :db/id))
retract-history-tx (map (fn [history] [:db/retractEntity (:db/id history)])
history-entities)
delete-views (->>
(mapcat
(fn [item]

View File

@@ -24,3 +24,26 @@
extra (delete-blocks/update-refs-history @conn retracts {})]
(d/transact! conn (concat retracts extra))
(is (nil? (d/entity @conn (:db/id reaction-entity)))))))
(deftest delete-blocks-removes-history-with-ref-value
(testing "property history entries referencing a deleted block are retracted"
(let [conn (db-test/create-conn-with-blocks
{:pages-and-blocks
[{:page {:block/title "Page"}
:blocks [{:block/title "Target block"}
{:block/title "Choice value"}]}]})
target-block (db-test/find-block-by-content @conn "Target block")
choice-value-block (db-test/find-block-by-content @conn "Choice value")
history-uuid (random-uuid)
now (common-util/time-ms)
_ (d/transact! conn [{:block/uuid history-uuid
:block/created-at now
:block/updated-at now
:logseq.property.history/block (:db/id target-block)
:logseq.property.history/property (:db/id (d/entity @conn :logseq.property/status))
:logseq.property.history/ref-value (:db/id choice-value-block)}])
history-entity (d/entity @conn [:block/uuid history-uuid])
retracts [[:db/retractEntity (:db/id choice-value-block)]]
extra (delete-blocks/update-refs-history @conn retracts {})]
(d/transact! conn (concat retracts extra))
(is (nil? (d/entity @conn (:db/id history-entity)))))))