perf(dupe-delete): use bulk_delete_findings + correlated subquery in async_dupe_delete#14797
Open
valentijnscholten wants to merge 1 commit intoDefectDojo:devfrom
Open
Conversation
…async_dupe_delete Replace per-row Finding.delete() loop with bulk_delete_findings (raw SQL cascade) and move excess-duplicate selection fully into the DB via a correlated subquery that counts newer siblings per original. select_related + only() eliminate the N+1 product lookup.
Maffooch
approved these changes
May 4, 2026
blakeaowens
approved these changes
May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Usually the number of findings deleted in the asyn delete job is small, but let's use the optimized cascade_delete method anyway to make it efficient.
Finding.delete()loop inasync_dupe_deletewithbulk_delete_findings, which uses raw SQL cascade (cascade_delete_related_objects) instead of Django's per-object Collector.newer_cnt >= max_dupes, eliminating the Python-side per-original counting loop.select_related("test__engagement__product")+only("id", "test_id")to the collection pass to avoid N+1 product lookups.original_findingis empty), so skippingfinding_delete()'s duplicate-cluster reconfiguration is safe.