|
6 | 6 | from django.db.models.query_utils import Q |
7 | 7 |
|
8 | 8 | import dojo.finding.helper as finding_helper |
| 9 | +from dojo import tag_inheritance |
9 | 10 | from dojo.celery_dispatch import dojo_dispatch_task |
10 | 11 | from dojo.finding.deduplication import ( |
11 | 12 | find_candidates_for_deduplication_hash, |
@@ -107,43 +108,51 @@ def process_scan( |
107 | 108 | # Get the findings from the parser based on what methods the parser supplies |
108 | 109 | # This could either mean traditional file parsing, or API pull parsing |
109 | 110 | parsed_findings = self.parse_findings(scan, parser) or [] |
110 | | - ( |
111 | | - new_findings, |
112 | | - reactivated_findings, |
113 | | - findings_to_mitigate, |
114 | | - untouched_findings, |
115 | | - ) = self.process_findings(parsed_findings, **kwargs) |
116 | | - # Close any old findings in the processed list if the the user specified for that |
117 | | - # to occur in the form that is then passed to the kwargs |
118 | | - closed_findings = self.close_old_findings(findings_to_mitigate, **kwargs) |
119 | | - # Update the timestamps of the test object by looking at the findings imported |
120 | | - logger.debug("REIMPORT_SCAN: Updating test/engagement timestamps") |
121 | | - # Update the timestamps of the test object by looking at the findings imported |
122 | | - self.update_timestamps() |
123 | | - # Update the test meta |
124 | | - self.update_test_meta() |
125 | | - # Update the test tags |
126 | | - self.update_test_tags() |
127 | | - # Save the test and engagement for changes to take affect |
128 | | - self.test.save() |
129 | | - self.test.engagement.save() |
130 | | - logger.debug("REIMPORT_SCAN: Updating test tags") |
131 | | - # Create a test import history object to record the flags sent to the importer |
132 | | - # This operation will return None if the user does not have the import history |
133 | | - # feature enabled |
134 | | - test_import_history = self.update_import_history( |
135 | | - new_findings=new_findings, |
136 | | - closed_findings=closed_findings, |
137 | | - reactivated_findings=reactivated_findings, |
138 | | - untouched_findings=untouched_findings, |
139 | | - ) |
140 | | - # Apply tags to findings and endpoints |
141 | | - self.apply_import_tags( |
142 | | - new_findings=new_findings, |
143 | | - closed_findings=closed_findings, |
144 | | - reactivated_findings=reactivated_findings, |
145 | | - untouched_findings=untouched_findings, |
146 | | - ) |
| 111 | + # Suppress per-row tag-inheritance signal work during the reimport |
| 112 | + # hot loop. Inheritance is applied in bulk after the batch via |
| 113 | + # `tag_inheritance.flush_for_product`. See default_importer for the |
| 114 | + # rationale. |
| 115 | + with tag_inheritance.batch(): |
| 116 | + ( |
| 117 | + new_findings, |
| 118 | + reactivated_findings, |
| 119 | + findings_to_mitigate, |
| 120 | + untouched_findings, |
| 121 | + ) = self.process_findings(parsed_findings, **kwargs) |
| 122 | + # Close any old findings in the processed list if the the user specified for that |
| 123 | + # to occur in the form that is then passed to the kwargs |
| 124 | + closed_findings = self.close_old_findings(findings_to_mitigate, **kwargs) |
| 125 | + # Update the timestamps of the test object by looking at the findings imported |
| 126 | + logger.debug("REIMPORT_SCAN: Updating test/engagement timestamps") |
| 127 | + # Update the timestamps of the test object by looking at the findings imported |
| 128 | + self.update_timestamps() |
| 129 | + # Update the test meta |
| 130 | + self.update_test_meta() |
| 131 | + # Update the test tags |
| 132 | + self.update_test_tags() |
| 133 | + # Save the test and engagement for changes to take affect |
| 134 | + self.test.save() |
| 135 | + self.test.engagement.save() |
| 136 | + logger.debug("REIMPORT_SCAN: Updating test tags") |
| 137 | + # Create a test import history object to record the flags sent to the importer |
| 138 | + # This operation will return None if the user does not have the import history |
| 139 | + # feature enabled |
| 140 | + test_import_history = self.update_import_history( |
| 141 | + new_findings=new_findings, |
| 142 | + closed_findings=closed_findings, |
| 143 | + reactivated_findings=reactivated_findings, |
| 144 | + untouched_findings=untouched_findings, |
| 145 | + ) |
| 146 | + # Apply tags to findings and endpoints |
| 147 | + self.apply_import_tags( |
| 148 | + new_findings=new_findings, |
| 149 | + closed_findings=closed_findings, |
| 150 | + reactivated_findings=reactivated_findings, |
| 151 | + untouched_findings=untouched_findings, |
| 152 | + ) |
| 153 | + # Bulk-apply tag inheritance for all children of the product touched |
| 154 | + # by this reimport. |
| 155 | + tag_inheritance.flush_for_product(self.test.engagement.product) |
147 | 156 | # Send out som notifications to the user |
148 | 157 | logger.debug("REIMPORT_SCAN: Generating notifications") |
149 | 158 | updated_count = ( |
|
0 commit comments