Further improve average remediation time queries#1778
Open
Hubtrick-Git wants to merge 5 commits intomainfrom
Open
Further improve average remediation time queries#1778Hubtrick-Git wants to merge 5 commits intomainfrom
Hubtrick-Git wants to merge 5 commits intomainfrom
Conversation
Collaborator
Hubtrick-Git
commented
Mar 6, 2026
- We do not need to run the same query 8 times to check different risk/cvss ranges, rather we can just use conditional aggregation to do this for us.
- This improves the speed drastically since we only need to do 1/8 of the queries and we can also cut down a lot of duplicate code in different parts
- Also refactored parts relying on these queries
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors average remediation time (fixing time) calculations to use a single SQL query with conditional aggregation, reducing repeated queries and consolidating returned metrics for both risk score and CVSS bands.
Changes:
- Replace per-severity average-fixing-time queries with one aggregated query returning multiple buckets at once.
- Introduce
dtos.RemediationTimeAveragesto carry risk/CVSS bucket averages. - Refactor controllers/services to remove now-redundant severity-based average-fixing-time methods and wire the new return type through.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| shared/common_interfaces.go | Updates repository/service interfaces to reflect the new aggregated return type and removes artifact-scoped CVSS method. |
| services/statistics_service.go | Removes artifact-scoped severity/CVSS average-fixing-time methods (no longer needed with aggregated query). |
| dtos/statistics_dto.go | Adds RemediationTimeAverages DTO for bucketed averages. |
| database/repositories/statistics_repository.go | Implements conditional-aggregation SQL returning all risk/CVSS averages in one call. |
| controllers/statistics_controller.go | Changes the average-fixing-time endpoint to return the aggregated DTO and removes severity handling. |
| controllers/artifact_controller.go | Uses aggregated averages in PDF report generation and adds a parsing helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.