fix create alert bulk for decisions insertion (#1107)

* fix create alert bulk for decisions insertion
This commit is contained in:
AlteredCoder 2021-12-16 18:26:19 +01:00 committed by GitHub
parent ec53fbfdab
commit d913ac160e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -296,7 +296,6 @@ func chunkDecisions(decisions []*ent.Decision, chunkSize int) [][]*ent.Decision
}
func (c *Client) CreateAlertBulk(machineId string, alertList []*models.Alert) ([]string, error) {
ret := []string{}
bulkSize := 20
@ -504,15 +503,14 @@ func (c *Client) CreateAlertBulk(machineId string, alertList []*models.Alert) ([
if err != nil {
return []string{}, errors.Wrapf(BulkError, "bulk creating alert : %s", err)
}
for _, a := range alerts {
for alertIndex, a := range alerts {
ret = append(ret, strconv.Itoa(a.ID))
for _, d := range alertDecisions {
decisionsChunk := chunkDecisions(d, bulkSize)
for _, d2 := range decisionsChunk {
_, err := c.Ent.Alert.Update().Where(alert.IDEQ(a.ID)).AddDecisions(d2...).Save(c.CTX)
if err != nil {
return []string{}, fmt.Errorf("error while updating decisions: %s", err.Error())
}
d := alertDecisions[alertIndex]
decisionsChunk := chunkDecisions(d, bulkSize)
for _, d2 := range decisionsChunk {
_, err := c.Ent.Alert.Update().Where(alert.IDEQ(a.ID)).AddDecisions(d2...).Save(c.CTX)
if err != nil {
return []string{}, fmt.Errorf("error while updating decisions: %s", err.Error())
}
}
}
@ -531,15 +529,14 @@ func (c *Client) CreateAlertBulk(machineId string, alertList []*models.Alert) ([
return []string{}, errors.Wrapf(BulkError, "leftovers creating alert : %s", err)
}
for _, a := range alerts {
for alertIndex, a := range alerts {
ret = append(ret, strconv.Itoa(a.ID))
for _, d := range alertDecisions {
decisionsChunk := chunkDecisions(d, bulkSize)
for _, d2 := range decisionsChunk {
_, err := c.Ent.Alert.Update().Where(alert.IDEQ(a.ID)).AddDecisions(d2...).Save(c.CTX)
if err != nil {
return []string{}, fmt.Errorf("error while updating decisions: %s", err.Error())
}
d := alertDecisions[alertIndex]
decisionsChunk := chunkDecisions(d, bulkSize)
for _, d2 := range decisionsChunk {
_, err := c.Ent.Alert.Update().Where(alert.IDEQ(a.ID)).AddDecisions(d2...).Save(c.CTX)
if err != nil {
return []string{}, fmt.Errorf("error while updating decisions: %s", err.Error())
}
}
}