fix: hash vuln db only once on load (#2054)

Signed-off-by: Lucas Rodriguez <lucas.rodriguez9616@gmail.com>
This commit is contained in:
Lucas Rodriguez 2024-09-17 14:04:51 -05:00 committed by GitHub
parent 1fb6199dd2
commit 60c0682bb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View file

@ -122,7 +122,7 @@ func (c *Curator) Status() Status {
SchemaVersion: metadata.Version,
Location: c.dbDir,
Checksum: metadata.Checksum,
Err: c.Validate(),
Err: nil,
}
}

View file

@ -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)
}
}
}