From 60874a2e86db0ab242921bcd5a6290a9fa0f991e Mon Sep 17 00:00:00 2001 From: Patrik Segedy Date: Tue, 18 Jun 2024 15:38:32 +0200 Subject: [PATCH] RHINENG-10791: common installable/applicable packages join --- base/database/utils.go | 5 +++++ manager/controllers/package_systems.go | 5 ++--- manager/controllers/system_packages.go | 4 +--- 3 files changed, 8 insertions(+), 6 deletions(-) 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).