From a07275eb66d3026c2e65a5891665bf5f556fca87 Mon Sep 17 00:00:00 2001 From: Agustin Groh Date: Mon, 6 Apr 2026 14:01:21 -0300 Subject: [PATCH] fix(all_urls):SP-4237 add is_mined and package_hash filter conditions to all_urls queries --- CHANGELOG.md | 7 ++++++- pkg/models/all_urls.go | 15 +++++++++++---- pkg/services/component.go | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c534ed..da3de00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.10.0] - 2026-04-06 +### Fixed +- Added `is_mined != false AND package_hash != ''` filter conditions to `GetURLsByPurlNameType`, `GetURLsByPurlNameTypeVersion`, and `GetVersionsByPurlNameType` queries to exclude unmined and empty-hash records + ## [0.9.0] - 2026-04-01 ### Added - Added `GetSPDXLicenseDetails` method in `LicenseModel` to retrieve SPDX license details by ID from the `spdx_license_data` table @@ -107,4 +111,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [0.6.0]: https://github.com/scanoss/go-models/compare/v0.5.1...v0.6.0 [0.7.0]: https://github.com/scanoss/go-models/compare/v0.6.0...v0.7.0 [0.8.0]: https://github.com/scanoss/go-models/compare/v0.7.0...v0.8.0 -[0.9.0]: https://github.com/scanoss/go-models/compare/v0.8.0...v0.9.0 \ No newline at end of file +[0.9.0]: https://github.com/scanoss/go-models/compare/v0.8.0...v0.9.0 +[0.10.0]: https://github.com/scanoss/go-models/compare/v0.9.0...v0.10.0 \ No newline at end of file diff --git a/pkg/models/all_urls.go b/pkg/models/all_urls.go index c4808e5..dc4cf8b 100644 --- a/pkg/models/all_urls.go +++ b/pkg/models/all_urls.go @@ -71,7 +71,9 @@ func (m *AllUrlsModel) GetURLsByPurlNameType(ctx context.Context, purlName, purl " LEFT JOIN mines m ON u.mine_id = m.id" + " LEFT JOIN licenses l ON u.license_id = l.id" + " LEFT JOIN versions v ON u.version_id = v.id" + - " WHERE m.purl_type = $1 AND u.purl_name = $2 ORDER BY date DESC" + " WHERE m.purl_type = $1 AND u.purl_name = $2" + + " AND u.is_mined != false AND u.package_hash != ''" + + " ORDER BY date DESC" var allUrls []AllURL err := m.db.SelectContext(ctx, &allUrls, query, purlType, purlName) @@ -109,7 +111,9 @@ func (m *AllUrlsModel) GetURLsByPurlNameTypeVersion(ctx context.Context, purlNam " LEFT JOIN mines m ON u.mine_id = m.id" + " LEFT JOIN licenses l ON u.license_id = l.id" + " LEFT JOIN versions v ON u.version_id = v.id" + - " WHERE m.purl_type = $1 AND u.purl_name = $2 AND (v.version_name = $3 OR v.version_name = $4) ORDER BY date DESC" + " WHERE m.purl_type = $1 AND u.purl_name = $2 AND (v.version_name = $3 OR v.version_name = $4)" + + " AND u.is_mined != false AND u.package_hash != ''" + + " ORDER BY date DESC" var allUrls []AllURL err := m.db.SelectContext(ctx, &allUrls, query, purlType, purlName, purlVersion, semverV) @@ -140,7 +144,9 @@ func (m *AllUrlsModel) GetVersionsByPurlNameType(ctx context.Context, purlName, " LEFT JOIN mines m ON u.mine_id = m.id" + " LEFT JOIN licenses l ON u.license_id = l.id" + " LEFT JOIN versions v ON u.version_id = v.id" + - " WHERE m.purl_type = $1 AND u.purl_name = $2 ORDER BY date DESC" + " WHERE m.purl_type = $1 AND u.purl_name = $2" + + " AND u.is_mined != false AND u.package_hash != ''" + + " ORDER BY date DESC" var allUrls []AllURL err := m.db.SelectContext(ctx, &allUrls, query, purlType, purlName) @@ -169,7 +175,8 @@ func (m *AllUrlsModel) CheckPurlByNameType(ctx context.Context, purlName string, "SELECT EXISTS("+ "SELECT 1 FROM all_urls au"+ " INNER JOIN mines m ON au.mine_id = m.id"+ - " WHERE au.purl_name = $1 AND m.purl_type = $2)", + " WHERE au.purl_name = $1 AND m.purl_type = $2"+ + " AND au.is_mined != false AND au.package_hash != '')", purlName, purlType).Scan(&exists) if err != nil { s.Errorf("Error: Failed to query all_urls table for %v, %v: %v", purlName, purlType, err) diff --git a/pkg/services/component.go b/pkg/services/component.go index 0569f48..dbb0801 100644 --- a/pkg/services/component.go +++ b/pkg/services/component.go @@ -175,7 +175,7 @@ func (cs *ComponentService) GetComponentVersions(ctx context.Context, purl strin func (cs *ComponentService) pickOneUrl(ctx context.Context, allUrls []models.AllURL, purlName, purlType, purlReq string) (models.AllURL, error) { s := ctxzap.Extract(ctx).Sugar() - + s.Debugf("Picking one URL from %v", allUrls) if len(allUrls) == 0 { s.Infof("No component match (in urls) found for %v, %v", purlName, purlType) return models.AllURL{}, ErrVersionNotFound