mirror of
https://github.com/logseq/logseq.git
synced 2026-05-19 18:32:41 +00:00
fix: invalid data when deleting closed value
fixes https://github.com/logseq/db-test/issues/729
This commit is contained in:
10
deps/db/src/logseq/db/common/delete_blocks.cljs
vendored
10
deps/db/src/logseq/db/common/delete_blocks.cljs
vendored
@@ -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]
|
||||
|
||||
@@ -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)))))))
|
||||
|
||||
Reference in New Issue
Block a user