Skip to content

Commit f5bc928

Browse files
committed
RHINENG-22325: use only necessary subset of Template attributes for Inventory Views
1 parent 8b04ce4 commit f5bc928

4 files changed

Lines changed: 25 additions & 15 deletions

File tree

base/database/testing.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,12 @@ func DeleteSystem(t *testing.T, inventoryID string) {
400400

401401
func CreateTemplate(t *testing.T, account int, uuid string, inventoryIDs []string) {
402402
template := &models.Template{
403-
RhAccountID: account, UUID: uuid, Name: uuid, EnvironmentID: strings.ReplaceAll(uuid, "-", ""),
404-
Arch: "x86_64", Version: "8",
403+
TemplateBase: models.TemplateBase{
404+
RhAccountID: account, UUID: uuid, Name: uuid,
405+
},
406+
EnvironmentID: strings.ReplaceAll(uuid, "-", ""),
407+
Arch: "x86_64",
408+
Version: "8",
405409
}
406410

407411
tx := DB.Begin()

base/inventory_views/inventory_views.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type InventoryViewsEvent struct {
3636
}
3737

3838
func MakeInventoryViewsHosts(systems []models.SystemPlatform,
39-
templates map[int64]models.Template) []InventoryViewsHost {
39+
templates map[int64]models.TemplateBase) []InventoryViewsHost {
4040
hosts := make([]InventoryViewsHost, len(systems))
4141
for i, system := range systems {
4242
hosts[i] = InventoryViewsHost{
@@ -70,7 +70,7 @@ func MakeInventoryViewsHosts(systems []models.SystemPlatform,
7070
return hosts
7171
}
7272

73-
func FindSystemsTemplates(tx *gorm.DB, systems []models.SystemPlatform) (map[int64]models.Template, error) {
73+
func FindSystemsTemplates(tx *gorm.DB, systems []models.SystemPlatform) (map[int64]models.TemplateBase, error) {
7474
templateIDs := make([]int64, 0, len(systems))
7575
if len(systems) == 0 {
7676
return nil, nil
@@ -85,15 +85,15 @@ func FindSystemsTemplates(tx *gorm.DB, systems []models.SystemPlatform) (map[int
8585
if len(templateIDs) == 0 {
8686
return nil, nil
8787
}
88-
templates := make([]models.Template, 0, len(templateIDs))
89-
q := tx.Model(&models.Template{}).
88+
templates := make([]models.TemplateBase, 0, len(templateIDs))
89+
q := tx.Model(&models.TemplateBase{}).
9090
Where("rh_account_id = ? AND id IN (?)", systems[0].RhAccountID, templateIDs)
9191
err := q.Find(&templates).Error
9292
if err != nil {
9393
return nil, err
9494
}
9595

96-
templatesMap := make(map[int64]models.Template, len(templates))
96+
templatesMap := make(map[int64]models.TemplateBase, len(templates))
9797
for _, t := range templates {
9898
templatesMap[t.ID] = t
9999
}

base/models/models.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ func (Reporter) TableName() string {
2525
return "reporter"
2626
}
2727

28+
type TemplateBase struct {
29+
ID int64 `gorm:"primaryKey"`
30+
RhAccountID int `gorm:"primaryKey"`
31+
UUID string
32+
Name string
33+
}
34+
2835
type Template struct {
29-
ID int64 `gorm:"primaryKey"`
30-
RhAccountID int `gorm:"primaryKey"`
31-
UUID string
36+
TemplateBase
3237
EnvironmentID string
33-
Name string
3438
Arch string
3539
Version string
3640
// Config pgtype.JSONB // currently unused
@@ -40,7 +44,7 @@ type Template struct {
4044
LastEdited *time.Time
4145
}
4246

43-
func (Template) TableName() string {
47+
func (TemplateBase) TableName() string {
4448
return "template"
4549
}
4650

listener/templates.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,12 @@ func TemplateUpdate(template mqueue.TemplateResponse) error {
118118
}
119119

120120
row := models.Template{
121-
RhAccountID: accountID,
122-
UUID: template.UUID,
121+
TemplateBase: models.TemplateBase{
122+
RhAccountID: accountID,
123+
UUID: template.UUID,
124+
Name: template.Name,
125+
},
123126
EnvironmentID: template.EnvironmentID,
124-
Name: template.Name,
125127
Arch: template.Arch,
126128
Version: template.Version,
127129
//Config: nil,

0 commit comments

Comments
 (0)