Skip to content

Commit 34c5f8b

Browse files
simplify
1 parent b62cff6 commit 34c5f8b

File tree

3 files changed

+21
-32
lines changed

3 files changed

+21
-32
lines changed

dojo/decorators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ def __wrapper__(*args, **kwargs):
9494
kwargs=kwargs,
9595
)
9696

97+
if signature:
98+
return func.si(*args, **kwargs)
99+
97100
countdown = kwargs.pop("countdown", 0)
98101
if we_want_async(*args, func=func, **kwargs):
99102
# Return a signature for use in chord/group if requested
100-
if signature:
101-
return func.si(*args, **kwargs)
102103
# Execute the task
103104
return func.apply_async(args=args, kwargs=kwargs, countdown=countdown)
104105
return func(*args, **kwargs)

dojo/importers/default_importer.py

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Test_Import,
1616
)
1717
from dojo.notifications.helper import create_notification
18+
from dojo.decorators import we_want_async
1819
from dojo.validators import clean_tags
1920

2021
logger = logging.getLogger(__name__)
@@ -159,7 +160,7 @@ def process_findings(
159160
from dojo.finding import helper as finding_helper
160161
from dojo.models import Dojo_User
161162
from dojo.utils import calculate_grade, calculate_grade_signature
162-
task_signatures = []
163+
post_processing_task_signatures = []
163164

164165
"""
165166
Saves findings in memory that were parsed from the scan report into the database.
@@ -233,29 +234,17 @@ def process_findings(
233234

234235
# Collect finding for parallel processing - we'll process them all at once after the loop
235236
push_to_jira = self.push_to_jira and (not self.findings_groups_enabled or not self.group_by)
236-
# Process finding - either sync or async based on block_execution
237-
if Dojo_User.wants_block_execution(self.user):
238-
# This will run synchronously, but we still call the dojo_async decorated function to count the task
239-
finding_helper.post_process_finding_save(
237+
# Always create signatures - we'll execute them sync or async later
238+
post_processing_task_signatures.append(
239+
finding_helper.post_process_finding_save_signature(
240240
finding,
241241
dedupe_option=True,
242242
rules_option=True,
243243
product_grading_option=False,
244244
issue_updater_option=True,
245245
push_to_jira=push_to_jira,
246-
)
247-
else:
248-
# Add to task signatures for async execution
249-
task_signatures.append(
250-
finding_helper.post_process_finding_save_signature(
251-
finding,
252-
dedupe_option=True,
253-
rules_option=True,
254-
product_grading_option=False,
255-
issue_updater_option=True,
256-
push_to_jira=push_to_jira,
257-
),
258-
)
246+
),
247+
)
259248

260249
for (group_name, findings) in group_names_to_findings_dict.items():
261250
finding_helper.add_findings_to_auto_group(
@@ -273,19 +262,18 @@ def process_findings(
273262

274263
# Calculate product grade after all findings are processed
275264
product = self.test.engagement.product
276-
if task_signatures:
265+
if post_processing_task_signatures:
277266
# If we have async tasks, use chord to wait for them before calculating grade
278-
if Dojo_User.wants_block_execution(self.user):
279-
# Run the chord synchronously by passing sync=True to each task
280-
for task_sig in task_signatures:
281-
task_sig.apply_async(sync=True).get()
282-
calculate_grade(product, sync=True)
267+
if we_want_async(async_user=self.user):
268+
# Run the chord asynchronously and after completing post processing tasks, calculate grade ONCE
269+
chord(post_processing_task_signatures)(calculate_grade_signature(product))
283270
else:
284-
# Run the chord asynchronously
285-
chord(task_signatures)(calculate_grade_signature(product))
286-
else:
287-
# If everything was sync, calculate grade now as post processing is done
288-
calculate_grade(product)
271+
# Execute each task synchronously
272+
for task_sig in post_processing_task_signatures:
273+
task_sig()
274+
275+
# Calculate grade, which can be prelimary calculated before the async tasks have finished
276+
calculate_grade(product)
289277

290278
sync = kwargs.get("sync", True)
291279
if not sync:

unittests/test_importers_performance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def import_reimport_performance(self, expected_num_queries1, expected_num_async_
177177
def test_import_reimport_reimport_performance_async(self):
178178
self.import_reimport_performance(
179179
expected_num_queries1=684,
180-
expected_num_async_tasks1=11,
180+
expected_num_async_tasks1=12,
181181
expected_num_queries2=610,
182182
expected_num_async_tasks2=22,
183183
expected_num_queries3=292,

0 commit comments

Comments
 (0)