Skip to content

API Endpoint: Get Package Count by Ecosystem#1638

Merged
timbastin merged 2 commits into
mainfrom
endpoint-package-count-by-ecosystem
Feb 9, 2026
Merged

API Endpoint: Get Package Count by Ecosystem#1638
timbastin merged 2 commits into
mainfrom
endpoint-package-count-by-ecosystem

Conversation

@Hubtrick-Git
Copy link
Copy Markdown
Collaborator

Added endpoint to retrieve amount of affected packages by ecosystem for @juliankepka frontend page.

@Hubtrick-Git Hubtrick-Git self-assigned this Feb 5, 2026
Copilot AI review requested due to automatic review settings February 5, 2026 11:47
Copy link
Copy Markdown
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 adds a new API endpoint /vulndb/affected-package-distribution/ to retrieve the count of affected packages grouped by ecosystem. The endpoint is intended for use in a frontend dashboard to display vulnerability distribution statistics.

Changes:

  • Added new GET endpoint to the VulnDB router for retrieving ecosystem distribution
  • Extended VulnDBController constructor to accept AffectedComponentRepository dependency
  • Implemented GetEcosystemDistribution method that queries affected_components table and aggregates by ecosystem prefix

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
router/vulndb_router.go Registered new /affected-package-distribution/ GET route in VulnDB router
controllers/vulndb_controller.go Added affectedComponentRepository dependency, implemented GetEcosystemDistribution endpoint with SQL aggregation and manual JSON construction

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread controllers/vulndb_controller.go
Comment thread controllers/vulndb_controller.go
Comment thread controllers/vulndb_controller.go Outdated
Comment thread controllers/vulndb_controller.go
Comment on lines +167 to +168
sql := `SELECT ecosystem, COUNT(*) FROM affected_components GROUP BY ecosystem;`
err := c.affectedComponentRepository.GetDB(nil).Raw(sql).Find(&results).Error
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The query SELECT ecosystem, COUNT(*) FROM affected_components GROUP BY ecosystem performs a full table scan and aggregation on the affected_components table, which could become slow as the table grows. Consider these optimizations:

  1. Add an index on the ecosystem column if one doesn't already exist
  2. Consider caching this result since ecosystem distribution is relatively static data
  3. If the table is very large, consider using approximate counts or maintaining a materialized view

Since this appears to be a public endpoint (no authentication middleware on the vulndb router), performance is especially important to prevent potential DoS via repeated expensive queries.

Copilot uses AI. Check for mistakes.
}

// group ecosystem by prefix ecosystem string and return the equivalent json encoding
func buildResultsJSON(rows []ecosystemRow) string {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just marshal the map 🙂

@timbastin timbastin merged commit f5a8fc4 into main Feb 9, 2026
17 of 19 checks passed
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.

3 participants