fix(osvmatcher): dedupe bulk queries#2808
Conversation
98690df to
fdfc494
Compare
|
Rebased this on current main and refreshed the affected VCR cassettes/snapshots after resolving the cassette conflicts.\n\nFocused checks run locally:\n- |
…ries # Conflicts: # cmd/osv-scanner/scan/image/testdata/cassettes/TestCommand_OCIImage.yaml # cmd/osv-scanner/scan/image/testdata/cassettes/TestCommand_OCIImage_JSONFormat.yaml # cmd/osv-scanner/scan/source/__snapshots__/command_test.snap # cmd/osv-scanner/scan/source/testdata/cassettes/TestCommand.yaml # cmd/osv-scanner/scan/source/testdata/cassettes/TestCommand_Config_UnusedIgnores.yaml
another-rex
left a comment
There was a problem hiding this comment.
Thanks, LGTM. Going to fix the merge issues and we should be good to go.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2808 +/- ##
==========================================
+ Coverage 79.16% 79.20% +0.03%
==========================================
Files 122 122
Lines 8222 8250 +28
==========================================
+ Hits 6509 6534 +25
- Misses 1329 1332 +3
Partials 384 384 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Head branch was pushed to by a user without write access
|
Pushed a small follow-up commit to fix the Local checks run on macOS arm64 with Go 1.26.3:
The exact subtests that failed in the macOS CI log pass locally for me. The CI failure still looks like a VCR/deps.dev cassette mismatch after the cassette refresh, e.g. |
Overview
This fixes duplicate package queries being sent in the same OSV bulk request.
Fixes #2654
Details
When the scan input contains the same package more than once,
OSVMatchercurrently sends that same package/version query multiple times to OSV. That does not change the final result, but it does add unnecessary API work and makes larger scans do more work than needed.This PR deduplicates equivalent OSV queries before calling
BatchQueryPaging, then expands the hydrated results back to the original package order. That keeps the scanner output behavior the same while reducing duplicate requests.I also updated the cached matcher query collection to use the same query key, so it does not rely on pointer identity when collecting missing package queries.
Testing
go test ./internal/clients/clientimpl/osvmatcher.go test ./internal/clients/clientimpl/....Checklist
./scripts/run_lints.sh.go test ./internal/clients/clientimpl/....