Optimize prepare_duplicates_for_delete#14564
Open
valentijnscholten wants to merge 6 commits intoDefectDojo:bugfixfrom
Open
Optimize prepare_duplicates_for_delete#14564valentijnscholten wants to merge 6 commits intoDefectDojo:bugfixfrom
valentijnscholten wants to merge 6 commits intoDefectDojo:bugfixfrom
Conversation
Replace per-original O(n×m) loop with a single bulk UPDATE for inside-scope duplicate reset. Outside-scope reconfiguration still runs per-original but now uses .iterator() and .exists() to avoid loading full querysets into memory. Also adds WARN-level logging to fix_loop_duplicates for visibility into how often duplicate loops occur in production, and a comment on removeLoop explaining the optimization opportunity.
Remove redundant .exclude() and .exists() calls by leveraging the bulk UPDATE that already unlinks inside-scope duplicates. Add prefetch_related to fetch all reverse relations in a single query.
…plicate_cluster Use QuerySet.update() instead of mass_model_updater to re-point duplicates to the new original. Single SQL query instead of loading all findings into Python and calling bulk_update.
Remove reset_duplicate_before_delete, reset_duplicates_before_delete, and set_new_original — all replaced by bulk UPDATE in prepare_duplicates_for_delete and .update() in reconfigure_duplicate_cluster. Remove unused mass_model_updater import.
Member
Author
|
This is not needed if we decide to merge #14566 |
Contributor
|
Feels like #14566 would be a better approach. Will move this PR to the next milestone in case others have different opinions |
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
While working on optimizing the (hard) delete of findings, I found this optimization that can/should be its own PR.
prepare_duplicates_for_delete()with a single bulk UPDATE for inside-scope duplicate reset, significantly reducing query count for large deletion operationsfix_loop_duplicates()for production visibility into duplicate loop frequencyremoveLoop()documenting optimization opportunity