Skip to content

Commit eedab62

Browse files
committed
using distinct on asset id for vulnerability hints
1 parent 28a0a00 commit eedab62

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

internal/database/repositories/dependency_vuln_repository.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,17 @@ func (repository *dependencyVulnRepository) GetHintsInOrganizationForVuln(tx cor
295295
var hints common.DependencyVulnHints
296296
stateCounts := make([]stateCount, 0, 7)
297297

298-
err := repository.GetDB(tx).Debug().Raw(`SELECT d.state as "state", COUNT(d.state) as "count" FROM dependency_vulns d WHERE asset_id IN (
299-
SELECT id from assets WHERE project_id IN (
300-
SELECT id from projects WHERE organization_id = ?
301-
)
302-
) AND d.cve_id = ? AND d.component_purl = ? GROUP BY d.state`, orgID, cveID, pURL).Scan(&stateCounts).Error
298+
err := repository.GetDB(tx).Debug().Raw(`SELECT state, COUNT(*) as "count" FROM (
299+
SELECT DISTINCT d.asset_id, d.state as "state"
300+
FROM dependency_vulns d
301+
WHERE d.asset_id IN (
302+
SELECT id FROM assets WHERE project_id IN (
303+
SELECT id FROM projects WHERE organization_id = ?
304+
)
305+
)
306+
AND d.cve_id = ?
307+
AND d.component_purl = ?
308+
) AS distinct_deps GROUP BY state`, orgID, cveID, pURL).Scan(&stateCounts).Error
303309
if err != nil {
304310
return hints, err
305311
}

0 commit comments

Comments
 (0)