@@ -47,6 +47,9 @@ func (service *LicenseRiskService) FindLicenseRisksInComponents(assetVersion mod
4747 //collect all risks before saving to the database, should be more efficient
4848 allLicenseRisks := []models.LicenseRisk {}
4949 allVulnEvents := []models.VulnEvent {}
50+ // track which license risks we've already processed to prevent duplicates
51+ processedLicenseRisks := make (map [string ]struct {})
52+
5053 //go over every component and check if the license is a valid osi license; if not we can create a license risk with the provided information
5154 for _ , component := range components {
5255
@@ -66,11 +69,17 @@ func (service *LicenseRiskService) FindLicenseRisksInComponents(assetVersion mod
6669 FinalLicenseDecision : "" ,
6770 ComponentPurl : component .Purl ,
6871 }
69- allLicenseRisks = append (allLicenseRisks , licenseRisk )
70- ev := models .NewDetectedEvent (licenseRisk .CalculateHash (), models .VulnTypeLicenseRisk , "system" , common.RiskCalculationReport {}, scannerID )
71- // apply the event on the dependencyVuln
72- ev .Apply (& licenseRisk )
73- allVulnEvents = append (allVulnEvents , ev )
72+
73+ // Check if we've already processed this license risk to avoid duplicates
74+ riskHash := licenseRisk .CalculateHash ()
75+ if _ , processed := processedLicenseRisks [riskHash ]; ! processed {
76+ processedLicenseRisks [riskHash ] = struct {}{}
77+ allLicenseRisks = append (allLicenseRisks , licenseRisk )
78+ ev := models .NewDetectedEvent (riskHash , models .VulnTypeLicenseRisk , "system" , common.RiskCalculationReport {}, scannerID )
79+ // apply the event on the dependencyVuln
80+ ev .Apply (& licenseRisk )
81+ allVulnEvents = append (allVulnEvents , ev )
82+ }
7483 }
7584 }
7685 err = service .licenseRiskRepository .SaveBatch (nil , allLicenseRisks )
0 commit comments