Skip to content

feat: cache cve-ecosystem-distribution endpoint#2338

Open
domzoric wants to merge 1 commit into
l3montree-dev:mainfrom
domzoric:feat/cache-cve-ecosystem-distribution
Open

feat: cache cve-ecosystem-distribution endpoint#2338
domzoric wants to merge 1 commit into
l3montree-dev:mainfrom
domzoric:feat/cache-cve-ecosystem-distribution

Conversation

@domzoric

Copy link
Copy Markdown
Contributor

Summary

The /api/v1/vulndb/cve-ecosystem-distribution/ endpoint takes 15-20s per request because it aggregates the whole global vuln db every time (COUNT(DISTINCT cve_id) over the full cve_affected_component join table).

The data only changes when the vulndb mirror runs (~hourly) and has no org/user/request dimension, so this adds a single in-process cached value with a 1h TTL and singleflight to prevent concurrent recomputations — the same pattern already used for the org statistics cache in statistics_service.go. The query logic itself is unchanged, just extracted into computeCVEEcosystemDistribution.

The cache hangs off the controller as a pointer so the existing value-receiver methods don't copy the lock.

Tests

  • Unit tests for the cache (empty/valid/expired) and proof that a cache hit never touches the database
  • Integration test against a real Postgres (testcontainers): correct distribution incl. ecosystem lowercasing and merging of CVE + malicious package counts, and that a second call is served from cache
  • VulnDBController was added to the fx TestApp wiring for this

Closes #2222

The endpoint aggregates the whole global vuln db on every request,
which takes 15-20s. The data only changes when the vulndb mirror
runs (~hourly) and has no org/user/request dimension, so a single
in-process value with a 1h TTL and singleflight (same pattern as
the org statistics cache) serves it instantly after the first
computation.

Closes l3montree-dev#2222

Signed-off-by: domzoric <zoric.dominik0511@gmail.com>
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.

Cache cve-ecosystem-distribution endpoint

1 participant