-
Notifications
You must be signed in to change notification settings - Fork 711
perf(compliance-assessments): replace per-row progress walk with aggregate #4014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
2361de9
8887753
853d3c7
b1454aa
cf14a96
cb8cb16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7841,20 +7841,59 @@ def assign_attributes(target, attributes): | |
| ) | ||
| return requirement_assessments, assessment_source_dict | ||
|
|
||
| @property | ||
| def progress(self) -> int: | ||
| requirement_assessments = list( | ||
| self.get_requirement_assessments(include_non_assessable=False) | ||
| def _get_progress_counts(self) -> tuple[int, int]: | ||
| """ | ||
| Return (total, assessed) counts for assessable requirements | ||
| """ | ||
|
|
||
| requirements = RequirementAssessment.objects.filter( | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| compliance_assessment=self, requirement__assessable=True | ||
| ) | ||
| total_cnt = len(requirement_assessments) | ||
| assessed_cnt = len( | ||
| [ | ||
| r | ||
| for r in requirement_assessments | ||
| if (r.result != RequirementAssessment.Result.NOT_ASSESSED) | ||
| or r.score != None | ||
| ] | ||
|
|
||
| if not self.selected_implementation_groups: | ||
| counts = requirements.aggregate( | ||
| total=Count("id"), | ||
| assessed=Count( | ||
| "id", | ||
| filter=~Q(result=RequirementAssessment.Result.NOT_ASSESSED) | ||
| | Q(score__isnull=False), | ||
| ), | ||
| ) | ||
| return counts["total"], counts["assessed"] | ||
|
|
||
| selected_groups = set(self.selected_implementation_groups) | ||
| total = 0 | ||
| assessed = 0 | ||
| lightweight_requirements = ( | ||
| requirements.select_related("requirement") | ||
| .only( | ||
| "result", | ||
| "score", | ||
| "requirement_id", | ||
| "requirement__implementation_groups", | ||
| ) | ||
| .iterator() | ||
| ) | ||
|
|
||
| for requirement_assessment in lightweight_requirements: | ||
| requirement_groups = set( | ||
| requirement_assessment.requirement.implementation_groups or [] | ||
| ) | ||
| if selected_groups.isdisjoint(requirement_groups): | ||
| continue | ||
|
|
||
| total += 1 | ||
| if ( | ||
| requirement_assessment.result | ||
| != RequirementAssessment.Result.NOT_ASSESSED | ||
| ) or requirement_assessment.score is not None: | ||
| assessed += 1 | ||
|
Comment on lines
+7944
to
+7948
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The if (
requirement_assessment.result
!= RequirementAssessment.Result.NOT_ASSESSED
) or requirement_assessment.score is not None:
assessed += 1With the current code a requirement with a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be left as is, because sometimes, audits can be assessed by just giving a score to the requirement nodes without giving a specific result on them. Putting def progress(self) -> int:
requirement_assessments = list(
self.get_requirement_assessments(include_non_assessable=False)
)
total_cnt = len(requirement_assessments)
assessed_cnt = len(
[
r
for r in requirement_assessments
if (r.result != RequirementAssessment.Result.NOT_ASSESSED)
or r.score != None
]
)
return int((assessed_cnt / total_cnt) * 100) if total_cnt > 0 else 0We could've put if (
requirement_assessment.result
== RequirementAssessment.Result.NOT_ASSESSED
) and requirement_assessment.score is None:
continue
assessed += 1
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ab-smith can you confirm this? |
||
|
|
||
| return total, assessed | ||
|
|
||
| @property | ||
| def progress(self) -> int: | ||
| total_cnt, assessed_cnt = self._get_progress_counts() | ||
| return int((assessed_cnt / total_cnt) * 100) if total_cnt > 0 else 0 | ||
|
|
||
| @property | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.