diff --git a/base/database/utils.go b/base/database/utils.go index a7006af7c..51bb0e031 100644 --- a/base/database/utils.go +++ b/base/database/utils.go @@ -273,3 +273,8 @@ func JoinAdvisoryMetadata(tx *gorm.DB) *gorm.DB { func JoinAdvisoryType(tx *gorm.DB) *gorm.DB { return tx.Joins("JOIN advisory_type at ON am.advisory_type_id = at.id") } + +func JoinInstallableApplicablePackages(tx *gorm.DB) *gorm.DB { + return tx.Joins("LEFT JOIN package pi ON pi.id = spkg.installable_id"). + Joins("LEFT JOIN package pa ON pa.id = spkg.applicable_id") +} diff --git a/manager/controllers/package_systems.go b/manager/controllers/package_systems.go index fbc61ee2f..38e005f9e 100644 --- a/manager/controllers/package_systems.go +++ b/manager/controllers/package_systems.go @@ -62,10 +62,9 @@ func packagesByNameQuery(db *gorm.DB, pkgName string) *gorm.DB { func packageSystemsQuery(db *gorm.DB, acc int, groups map[string]string, packageName string, packageIDs []int, ) *gorm.DB { - query := database.SystemPackages(db, acc, groups, database.JoinTemplates). + query := database.SystemPackages(db, acc, groups, + database.JoinTemplates, database.JoinInstallableApplicablePackages). Select(PackageSystemsSelect). - Joins("LEFT JOIN package pi ON pi.id = spkg.installable_id"). - Joins("LEFT JOIN package pa ON pa.id = spkg.applicable_id"). Where("sp.stale = false"). Where("pn.name = ?", packageName). Where("spkg.package_id in (?)", packageIDs) diff --git a/manager/controllers/system_packages.go b/manager/controllers/system_packages.go index b03ddcc8c..613c3b2c0 100644 --- a/manager/controllers/system_packages.go +++ b/manager/controllers/system_packages.go @@ -57,9 +57,7 @@ type SystemPackageDBLoad struct { } func systemPackageQuery(db *gorm.DB, account int, groups map[string]string, inventoryID string) *gorm.DB { - query := database.SystemPackages(db, account, groups). - Joins("LEFT JOIN package pi ON pi.id = spkg.installable_id"). - Joins("LEFT JOIN package pa ON pa.id = spkg.applicable_id"). + query := database.SystemPackages(db, account, groups, database.JoinInstallableApplicablePackages). Joins("LEFT JOIN strings AS descr ON p.description_hash = descr.id"). Joins("LEFT JOIN strings AS sum ON p.summary_hash = sum.id"). Select(SystemPackagesSelect).