Skip to content

Commit 0cfdf0f

Browse files
authored
feat: alert count limit (#9621)
1 parent cca1863 commit 0cfdf0f

File tree

4 files changed

+219
-149
lines changed

4 files changed

+219
-149
lines changed

agent/app/repo/alert.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type IAlertRepo interface {
4242
CreateAlertTask(alertTaskBase *model.AlertTask) error
4343
DeleteAlertTask(opts ...DBOption) error
4444
GetAlertTask(opts ...DBOption) (model.AlertTask, error)
45-
LoadTaskCount(alertType string, project string) (uint, uint, error)
45+
LoadTaskCount(alertType string, project string, method string) (uint, uint, error)
4646
GetTaskLog(alertType string, alertId uint) (time.Time, error)
4747
GetLicensePushCount(method string) (uint, error)
4848

@@ -222,17 +222,17 @@ func (a *AlertRepo) GetAlertTask(opts ...DBOption) (model.AlertTask, error) {
222222
return data, err
223223
}
224224

225-
func (a *AlertRepo) LoadTaskCount(alertType string, project string) (uint, uint, error) {
225+
func (a *AlertRepo) LoadTaskCount(alertType string, project string, method string) (uint, uint, error) {
226226
var (
227227
todayCount int64
228228
totalCount int64
229229
)
230-
_ = global.AlertDB.Model(&model.AlertTask{}).Where("type = ? AND quota_type = ?", alertType, project).Count(&totalCount).Error
230+
_ = global.AlertDB.Model(&model.AlertTask{}).Where("type = ? AND quota_type = ? AND method = ?", alertType, project, method).Count(&totalCount).Error
231231

232232
now := time.Now()
233233
todayMidnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
234234
tomorrowMidnight := todayMidnight.Add(24 * time.Hour)
235-
err := global.AlertDB.Model(&model.AlertTask{}).Where("type = ? AND quota_type = ? AND created_at > ? AND created_at < ?", alertType, project, todayMidnight, tomorrowMidnight).Count(&todayCount).Error
235+
err := global.AlertDB.Model(&model.AlertTask{}).Where("type = ? AND quota_type = ? AND method = ? AND created_at > ? AND created_at < ?", alertType, project, method, todayMidnight, tomorrowMidnight).Count(&todayCount).Error
236236
return uint(todayCount), uint(totalCount), err
237237
}
238238

0 commit comments

Comments
 (0)