add an optional flag to disable the fetch (#2169)

This commit is contained in:
Thibault "bui" Koechlin 2023-04-14 11:39:16 +02:00 committed by GitHub
parent 66dfded0cf
commit 3041023ed8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -986,6 +986,7 @@ func (c *Client) TotalAlerts() (int, error) {
}
func (c *Client) QueryAlertWithFilter(filter map[string][]string) ([]*ent.Alert, error) {
sort := "DESC" // we sort by desc by default
if val, ok := filter["sort"]; ok {
if val[0] != "ASC" && val[0] != "DESC" {
@ -1011,8 +1012,15 @@ func (c *Client) QueryAlertWithFilter(filter map[string][]string) ([]*ent.Alert,
if err != nil {
return []*ent.Alert{}, err
}
//only if with_decisions is present and set to false, we exclude this
if val, ok := filter["with_decisions"]; ok && val[0] == "false" {
c.Log.Debugf("skipping decisions")
} else {
alerts = alerts.
WithDecisions()
}
alerts = alerts.
WithDecisions().
WithEvents().
WithMetas().
WithOwner()
@ -1283,6 +1291,8 @@ func (c *Client) FlushAlerts(MaxAge string, MaxItems int) error {
lastAlert, err := c.QueryAlertWithFilter(map[string][]string{
"sort": {"DESC"},
"limit": {"1"},
//we do not care about fetching the edges, we just want the id
"with_decisions": {"false"},
})
c.Log.Debugf("FlushAlerts (last alert): %+v", lastAlert)
if err != nil {