Skip to content

Commit

Permalink
fix: remove unused nameID2SrcNameIDs map
Browse files Browse the repository at this point in the history
  • Loading branch information
psegedy authored and jdobes committed Dec 4, 2024
1 parent d7f45c0 commit 7404e32
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
5 changes: 2 additions & 3 deletions vmaas/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ type Cache struct {

ArchCompat map[ArchID]map[ArchID]bool

PackageDetails map[PkgID]PackageDetail
Nevra2PkgID map[Nevra]PkgID
NameID2SrcNameIDs map[NameID]map[NameID]struct{}
PackageDetails map[PkgID]PackageDetail
Nevra2PkgID map[Nevra]PkgID

RepoIDs []RepoID
RepoDetails map[RepoID]RepoDetail
Expand Down
12 changes: 0 additions & 12 deletions vmaas/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ func loadPkgDetails(c *Cache) {
id2pkdDetail := make(map[PkgID]PackageDetail, cnt)
nevra2id := make(map[Nevra]PkgID, cnt)
srcPkgID2PkgID := make(map[PkgID][]PkgID, cntSrc)
nameID2SrcNameIDs := make(map[NameID]map[NameID]struct{})
var pkgID PkgID
for rows.Next() {
var det PackageDetail
Expand All @@ -343,16 +342,6 @@ func loadPkgDetails(c *Cache) {
continue
}

var srcNameID NameID
row := sqlDB.QueryRow("SELECT name_id FROM package_detail WHERE id = ?", *det.SrcPkgID)
if err := row.Scan(&srcNameID); err != nil {
panic(err)
}
if _, ok := nameID2SrcNameIDs[det.NameID]; !ok {
nameID2SrcNameIDs[det.NameID] = make(map[NameID]struct{})
}
nameID2SrcNameIDs[det.NameID][srcNameID] = struct{}{}

_, ok := srcPkgID2PkgID[*det.SrcPkgID]
if !ok {
srcPkgID2PkgID[*det.SrcPkgID] = []PkgID{}
Expand All @@ -365,7 +354,6 @@ func loadPkgDetails(c *Cache) {
c.PackageDetails = id2pkdDetail
c.Nevra2PkgID = nevra2id
c.SrcPkgID2PkgID = srcPkgID2PkgID
c.NameID2SrcNameIDs = nameID2SrcNameIDs
}

func loadRepoDetails(c *Cache) { //nolint: funlen
Expand Down
17 changes: 9 additions & 8 deletions vmaas/vulnerabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestCSAF(t *testing.T) {
unfixed := CSAFProduct{CpeID: 1, PackageNameID: 1}
fixed1 := CSAFProduct{CpeID: 1, PackageNameID: 1, PackageID: 1}
fixed2 := CSAFProduct{CpeID: 2, PackageNameID: 1, PackageID: 2}
var one PkgID = 1

c := Cache{
Arch2ID: map[string]ArchID{"x86_64": 1},
Expand All @@ -35,13 +36,9 @@ func TestCSAF(t *testing.T) {
{NameID: 2, EvrID: 1, ArchID: 1}: 3,
},
PackageDetails: map[PkgID]PackageDetail{
1: {NameID: 1, EvrID: 1, ArchID: 1}, // kernel-0:1-1
2: {NameID: 1, EvrID: 2, ArchID: 1}, // kernel-0:2-2
3: {NameID: 2, EvrID: 1, ArchID: 1}, // kernel-devel-0:1-1
},
NameID2SrcNameIDs: map[NameID]map[NameID]struct{}{
1: {1: struct{}{}},
2: {1: struct{}{}},
1: {NameID: 1, EvrID: 1, ArchID: 1, SrcPkgID: nil}, // kernel-0:1-1
2: {NameID: 1, EvrID: 2, ArchID: 1, SrcPkgID: nil}, // kernel-0:2-2
3: {NameID: 2, EvrID: 1, ArchID: 1, SrcPkgID: &one}, // kernel-devel-0:1-1
},
CSAFCVEs: map[CpeIDNameID]map[CSAFProduct]CSAFCVEs{
{CpeID: 1, NameID: 1}: {
Expand All @@ -58,6 +55,7 @@ func TestCSAF(t *testing.T) {
type expected struct {
pkg NevraString
nameID NameID
pkgID PkgID
fixed []CSAFProduct
unfixed []CSAFProduct
}
Expand All @@ -68,26 +66,29 @@ func TestCSAF(t *testing.T) {
{
pkg: NevraString{Nevra: pkg1, Pkg: pkg1.String()},
nameID: 1,
pkgID: 1,
unfixed: []CSAFProduct{unfixed},
fixed: []CSAFProduct{fixed1, fixed2},
},
{
pkg: NevraString{Nevra: pkg2, Pkg: pkg2.String()},
nameID: 1,
pkgID: 2,
unfixed: []CSAFProduct{unfixed},
fixed: []CSAFProduct{fixed1, fixed2},
},
{
pkg: NevraString{Nevra: pkg3, Pkg: pkg3.String()},
nameID: 2,
pkgID: 3,
unfixed: []CSAFProduct{unfixed},
fixed: []CSAFProduct{},
}, // match source package
}

products := make([]ProductsPackage, 0, len(matrix))
for _, m := range matrix {
pp := cpes2products(&c, []CpeID{1, 2}, m.nameID, []ModuleStream{ms}, m.pkg, &defaultOpts)
pp := cpes2products(&c, []CpeID{1, 2}, m.nameID, m.pkgID, []ModuleStream{ms}, m.pkg, &defaultOpts)
assert.Equal(t, m.fixed, pp.ProductsFixed)
assert.Equal(t, m.unfixed, pp.ProductsUnfixed)
products = append(products, pp)
Expand Down

0 comments on commit 7404e32

Please sign in to comment.