Skip to content

Commit

Permalink
RHINENG-2284: move subquery into SystemPackageDataShort()
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMraka committed Nov 27, 2023
1 parent 10e8d71 commit 11c6fb3
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions base/database/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,31 @@ func SystemAdvisories(tx *gorm.DB, accountID int, groups map[string]string) *gor
Joins("JOIN system_advisories sa on sa.system_id = sp.id AND sa.rh_account_id = ?", accountID)
}

func PackageSystemDataShort(tx *gorm.DB, accountID int) *gorm.DB {
return tx.Select(`pd.package_name_id as name_id,
jsonb_object_keys(pd.update_data)::bigint as system_id,
jsonb_path_query(update_data, '$.*') as update_data`).
Table("package_system_data pd").
Where("pd.rh_account_id = ?", accountID)
func SystemPackageDataShort(tx *gorm.DB, accountID int) *gorm.DB {
return tx.Select(`system_id,
jsonb_object_keys(update_data)::bigint as package_id,
jsonb_path_query(update_data, '$.*') as update_data`).
Table("system_package_data").
Where("rh_account_id = ?", accountID)
}

func SystemPackageData(tx *gorm.DB, accountID int, groups map[string]string) *gorm.DB {
spkg := SystemPackageDataShort(tx, accountID)
return Systems(tx, accountID, groups).
Joins(`JOIN (SELECT system_id,
jsonb_object_keys(update_data)::bigint as package_id,
jsonb_path_query(update_data, '$.*') as update_data
FROM system_package_data
WHERE rh_account_id = ?) as spkg
ON spkg.system_id = sp.id`, accountID).
Joins(`JOIN (?) as spkg
ON spkg.system_id = sp.id`, spkg).
Joins("JOIN package p on p.id = spkg.package_id").
Joins("JOIN package_name pn on pn.id = p.name_id")
}

func PackageSystemDataShort(tx *gorm.DB, accountID int) *gorm.DB {
return tx.Select(`pd.package_name_id as name_id,
jsonb_object_keys(pd.update_data)::bigint as system_id,
jsonb_path_query(update_data, '$.*') as update_data`).
Table("package_system_data pd").
Where("pd.rh_account_id = ?", accountID)
}

func PackageSystemData(tx *gorm.DB, accountID int, groups map[string]string) *gorm.DB {
spkg := PackageSystemDataShort(tx, accountID)
return Systems(tx, accountID, groups).
Expand Down

0 comments on commit 11c6fb3

Please sign in to comment.