refactor: change alert mute clean (#1140)

refactor: change alert mute clean
This commit is contained in:
Yening Qin 2022-09-01 11:18:04 +08:00 committed by GitHub
parent fc4c4b96bf
commit 09f37b8076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 9 deletions

View File

@ -126,13 +126,20 @@ func AlertMuteDel(ids []int64) error {
}
func AlertMuteStatistics(cluster string) (*Statistics, error) {
// clean expired first
buf := int64(30)
err := DB().Where("etime < ?", time.Now().Unix()-buf).Delete(new(AlertMute)).Error
if err != nil {
return nil, err
}
session := DB().Model(&AlertMute{}).Select("count(*) as total", "max(create_at) as last_updated")
if cluster != "" {
session = session.Where("(cluster like ? or cluster = ?)", "%"+cluster+"%", ClusterAll)
}
var stats []*Statistics
err := session.Find(&stats).Error
err = session.Find(&stats).Error
if err != nil {
return nil, err
}
@ -141,13 +148,6 @@ func AlertMuteStatistics(cluster string) (*Statistics, error) {
}
func AlertMuteGetsByCluster(cluster string) ([]*AlertMute, error) {
// clean expired first
buf := int64(30)
err := DB().Where("etime < ?", time.Now().Unix()+buf).Delete(new(AlertMute)).Error
if err != nil {
return nil, err
}
// get my cluster's mutes
session := DB().Model(&AlertMute{})
if cluster != "" {
@ -156,7 +156,7 @@ func AlertMuteGetsByCluster(cluster string) ([]*AlertMute, error) {
var lst []*AlertMute
var mlst []*AlertMute
err = session.Find(&lst).Error
err := session.Find(&lst).Error
if err != nil {
return nil, err
}