Skip to content

Commit 67b910f

Browse files
committed
RHINENG-21786: refactor advisory notification
so we can get rid of special handling of AdvisoryTypes
1 parent 24fa3c8 commit 67b910f

3 files changed

Lines changed: 6 additions & 41 deletions

File tree

base/database/setup.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package database
22

33
import (
4-
"app/base/models"
54
"app/base/utils"
65
"fmt"
76
"time"
@@ -23,7 +22,6 @@ var (
2322
DB *gorm.DB
2423
DBReadReplica *gorm.DB
2524
OtherAdvisoryTypes []string
26-
AdvisoryTypes map[int]string
2725
globalPgConfig map[DBMode]PostgreSQLConfig = make(map[DBMode]PostgreSQLConfig)
2826
)
2927

@@ -172,20 +170,4 @@ func loadAdditionalParamsFromDB() {
172170
if err != nil {
173171
panic(err)
174172
}
175-
176-
// Load AdvisoryTypes
177-
var types []models.AdvisoryType
178-
179-
err = DB.Table("advisory_type").
180-
Select("id, name").
181-
Scan(&types).Error
182-
utils.LogDebug("advisory_types", types, "Advisory types loaded from DB")
183-
if err != nil {
184-
panic(err)
185-
}
186-
187-
AdvisoryTypes = make(map[int]string)
188-
for _, at := range types {
189-
AdvisoryTypes[at.ID] = at.Name
190-
}
191173
}

base/database/setup_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package database
22

33
import (
44
"app/base/utils"
5-
"github.com/stretchr/testify/assert"
65
"testing"
6+
7+
"github.com/stretchr/testify/assert"
78
)
89

910
func TestDBCheck(t *testing.T) {
@@ -15,5 +16,5 @@ func TestAdditionalParams(t *testing.T) {
1516
utils.SkipWithoutDB(t)
1617
Configure()
1718

18-
assert.True(t, len(AdvisoryTypes) == 5)
19+
assert.True(t, len(OtherAdvisoryTypes) == 2)
1920
}

evaluator/notifications.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package evaluator
22

33
import (
44
"app/base"
5-
"app/base/database"
65
"app/base/models"
76
"app/base/mqueue"
87
ntf "app/base/notification"
@@ -32,35 +31,18 @@ func getUnnotifiedAdvisories(tx *gorm.DB, accountID int, newAdvs SystemAdvisoryM
3231
advIDs = append(advIDs, a.AdvisoryID)
3332
}
3433

35-
var advNames []string
3634
err := tx.Table("advisory_account_data as acd").
37-
Select("am.name").
35+
Select("am.id as advisory_id, am.name as advisory_name, at.name as advisory_type, am.synopsis").
3836
Joins("inner join advisory_metadata am on am.id = acd.advisory_id").
37+
Joins("inner join advisory_type at on at.id = am.advisory_type_id").
3938
Where("acd.rh_account_id = ? AND acd.advisory_id IN (?)"+
4039
"AND acd.notified IS NULL AND acd.systems_installable > 0", accountID, advIDs).
4140
Order("am.name ASC").
42-
Scan(&advNames).Error
41+
Scan(&unAdvs).Error
4342
if err != nil {
4443
return nil, errors.Wrap(err, "querying unnotified advisories from DB failed")
4544
}
4645

47-
if len(advNames) == 0 {
48-
return nil, nil
49-
}
50-
51-
for _, n := range advNames {
52-
if a, ok := newAdvs[n]; ok {
53-
unAdvs = append(
54-
unAdvs,
55-
ntf.Advisory{
56-
AdvisoryID: a.AdvisoryID,
57-
AdvisoryName: a.Advisory.Name,
58-
AdvisoryType: database.AdvisoryTypes[a.Advisory.AdvisoryTypeID],
59-
Synopsis: a.Advisory.Synopsis,
60-
})
61-
}
62-
}
63-
6446
return unAdvs, nil
6547
}
6648

0 commit comments

Comments
 (0)