Skip to content

Commit 4c43074

Browse files
committed
RHINENG-22325: use only necessary subset of Template attributes for Inventory Views
1 parent 2cec566 commit 4c43074

4 files changed

Lines changed: 21 additions & 11 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func FindSystemsTemplates(tx *gorm.DB, systems []models.SystemPlatform) (map[int
9292
return nil, err
9393
}
9494

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

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)