fix postgreSQL count fail (#1184)

This commit is contained in:
AlteredCoder 2022-01-19 14:50:53 +01:00 committed by GitHub
parent c81fc87d4e
commit b1a7ffb92f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -753,17 +753,20 @@ func (c *Client) QueryAlertWithFilter(filter map[string][]string) ([]*ent.Alert,
WithEvents().
WithMetas().
WithOwner()
if sort == "ASC" {
alerts = alerts.Order(ent.Asc(alert.FieldCreatedAt))
} else {
alerts = alerts.Order(ent.Desc(alert.FieldCreatedAt))
}
if limit == 0 {
limit, err = alerts.Count(c.CTX)
if err != nil {
return []*ent.Alert{}, fmt.Errorf("unable to count nb alerts: %s", err)
}
}
if sort == "ASC" {
alerts = alerts.Order(ent.Asc(alert.FieldCreatedAt))
} else {
alerts = alerts.Order(ent.Desc(alert.FieldCreatedAt))
}
result, err := alerts.Limit(paginationSize).Offset(offset).All(c.CTX)
if err != nil {
return []*ent.Alert{}, errors.Wrapf(QueryFail, "pagination size: %d, offset: %d: %s", paginationSize, offset, err)