Skip to content

Further improve average remediation time queries#1778

Open
Hubtrick-Git wants to merge 5 commits intomainfrom
further-improve-average-remediation-time-queries
Open

Further improve average remediation time queries#1778
Hubtrick-Git wants to merge 5 commits intomainfrom
further-improve-average-remediation-time-queries

Conversation

@Hubtrick-Git
Copy link
Collaborator

  • 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

Copilot AI review requested due to automatic review settings March 6, 2026 15:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.RemediationTimeAverages to 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants