Skip to content

Commit

Permalink
fix: hash vuln db only once on load (#2054)
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Rodriguez <[email protected]>
  • Loading branch information
lucasrod16 authored Sep 17, 2024
1 parent 1fb6199 commit 60c0682
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 @@ -122,7 +122,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 60c0682

Please sign in to comment.