Skip to content

Commit

Permalink
fix: hash vuln db only once on load
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Rodriguez <[email protected]>
  • Loading branch information
lucasrod16 committed Sep 8, 2024
1 parent 7dfa436 commit d94742b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion grype/db/curator.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (c *Curator) Status() Status {
SchemaVersion: metadata.Version,
Location: c.dbDir,
Checksum: metadata.Checksum,
Err: c.Validate(),
Err: nil,
}
}

Expand Down
26 changes: 26 additions & 0 deletions grype/load_vulnerability_db_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package grype

import (
"path/filepath"
"testing"

"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/internal"
)

// this benchmark was added to measure the performance
// of LoadVulnerabilityDB, specifically in regards to hash validation.
// https://github.com/anchore/grype/issues/1502
func BenchmarkLoadVulnerabilityDB(b *testing.B) {
cfg := db.Config{
DBRootDir: filepath.Join(".tmp", "grype-db"),
ListingURL: internal.DBUpdateURL,
ValidateByHashOnGet: true,
}
for range b.N {
_, _, _, err := LoadVulnerabilityDB(cfg, true)
if err != nil {
b.Fatal(err)
}
}
}

0 comments on commit d94742b

Please sign in to comment.