From 7404e32fd4c5476b4b2485907239f22c924f0bca Mon Sep 17 00:00:00 2001 From: Patrik Segedy Date: Mon, 2 Dec 2024 18:12:50 +0100 Subject: [PATCH] fix: remove unused nameID2SrcNameIDs map --- vmaas/cache.go | 5 ++--- vmaas/load.go | 12 ------------ vmaas/vulnerabilities_test.go | 17 +++++++++-------- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/vmaas/cache.go b/vmaas/cache.go index 9e061e1..d30a713 100644 --- a/vmaas/cache.go +++ b/vmaas/cache.go @@ -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 diff --git a/vmaas/load.go b/vmaas/load.go index 762de33..9c102b2 100644 --- a/vmaas/load.go +++ b/vmaas/load.go @@ -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 @@ -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{} @@ -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 diff --git a/vmaas/vulnerabilities_test.go b/vmaas/vulnerabilities_test.go index 7e6fd12..f44013f 100644 --- a/vmaas/vulnerabilities_test.go +++ b/vmaas/vulnerabilities_test.go @@ -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}, @@ -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}: { @@ -58,6 +55,7 @@ func TestCSAF(t *testing.T) { type expected struct { pkg NevraString nameID NameID + pkgID PkgID fixed []CSAFProduct unfixed []CSAFProduct } @@ -68,18 +66,21 @@ 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 @@ -87,7 +88,7 @@ func TestCSAF(t *testing.T) { 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)