File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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]
Original file line number Diff line number Diff line change 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)))))))
You can’t perform that action at this time.
0 commit comments