Commit 44caf6d
committed
perf: address PR review feedback for large-scale delete safety
- Stream finding IDs via iterator()+batched instead of materializing
the full ID list into memory. Prevents OOM on 4.5M+ finding deletes.
- Add SET LOCAL statement_timeout (300s) and deadlock error logging to
cascade_delete SQL execution. Prevents runaway queries from holding
locks indefinitely and surfaces deadlock errors in logs.
- Reuse scope_ids subquery variable and replace .exists()+.count()
with a single .count() call to avoid evaluating the subquery twice.
- Add comment explaining why FileUpload uses per-object ORM delete
(custom delete() removes files from disk; file attachments are rare).
- Scope fix_loop_duplicates to the deletion set instead of scanning
the full findings table. The double self-join is cheap when filtered
to only findings in the scope being deleted.
- Document that pre_bulk_delete_findings signal receivers must not
materialize the full queryset (use .filter()/.iterator() instead).
- Add skip_m2m_for parameter to cascade_delete so bulk_delete_findings
can tell it Finding M2M was already cleaned by bulk_clear_finding_m2m,
avoiding redundant tag count aggregation queries.1 parent 161abd0 commit 44caf6d
4 files changed
Lines changed: 71 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
632 | 632 | | |
633 | 633 | | |
634 | 634 | | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | 635 | | |
640 | 636 | | |
641 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
642 | 642 | | |
643 | 643 | | |
644 | 644 | | |
| |||
747 | 747 | | |
748 | 748 | | |
749 | 749 | | |
750 | | - | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
751 | 754 | | |
752 | 755 | | |
753 | 756 | | |
| |||
771 | 774 | | |
772 | 775 | | |
773 | 776 | | |
774 | | - | |
775 | | - | |
776 | | - | |
777 | | - | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
778 | 785 | | |
779 | | - | |
| 786 | + | |
780 | 787 | | |
781 | | - | |
782 | | - | |
| 788 | + | |
| 789 | + | |
783 | 790 | | |
784 | 791 | | |
785 | 792 | | |
786 | | - | |
| 793 | + | |
787 | 794 | | |
788 | 795 | | |
789 | 796 | | |
790 | | - | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
791 | 800 | | |
792 | 801 | | |
793 | | - | |
| 802 | + | |
794 | 803 | | |
795 | 804 | | |
796 | 805 | | |
797 | 806 | | |
798 | | - | |
| 807 | + | |
799 | 808 | | |
800 | 809 | | |
801 | 810 | | |
802 | | - | |
803 | | - | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
804 | 815 | | |
805 | 816 | | |
806 | 817 | | |
807 | 818 | | |
808 | | - | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
809 | 823 | | |
810 | 824 | | |
811 | 825 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2094 | 2094 | | |
2095 | 2095 | | |
2096 | 2096 | | |
| 2097 | + | |
2097 | 2098 | | |
2098 | | - | |
2099 | | - | |
| 2099 | + | |
| 2100 | + | |
2100 | 2101 | | |
2101 | 2102 | | |
2102 | | - | |
2103 | | - | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
2104 | 2106 | | |
2105 | 2107 | | |
2106 | 2108 | | |
| |||
2109 | 2111 | | |
2110 | 2112 | | |
2111 | 2113 | | |
| 2114 | + | |
| 2115 | + | |
2112 | 2116 | | |
2113 | 2117 | | |
2114 | 2118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
38 | 41 | | |
39 | 42 | | |
40 | | - | |
41 | | - | |
42 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
43 | 51 | | |
44 | 52 | | |
45 | 53 | | |
| |||
52 | 60 | | |
53 | 61 | | |
54 | 62 | | |
55 | | - | |
| 63 | + | |
56 | 64 | | |
57 | 65 | | |
58 | 66 | | |
| |||
67 | 75 | | |
68 | 76 | | |
69 | 77 | | |
| 78 | + | |
| 79 | + | |
70 | 80 | | |
71 | 81 | | |
72 | 82 | | |
| |||
76 | 86 | | |
77 | 87 | | |
78 | 88 | | |
| 89 | + | |
| 90 | + | |
79 | 91 | | |
80 | 92 | | |
81 | 93 | | |
| |||
122 | 134 | | |
123 | 135 | | |
124 | 136 | | |
| 137 | + | |
125 | 138 | | |
126 | 139 | | |
127 | 140 | | |
| |||
139 | 152 | | |
140 | 153 | | |
141 | 154 | | |
142 | | - | |
143 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
144 | 158 | | |
145 | | - | |
| 159 | + | |
146 | 160 | | |
147 | 161 | | |
148 | | - | |
| 162 | + | |
149 | 163 | | |
150 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
151 | 168 | | |
152 | 169 | | |
153 | 170 | | |
| |||
0 commit comments