| 25 | } |
| 26 | |
| 27 | func (c *Client) QueryAllDecisionsWithFilters(ctx context.Context, now time.Time, filter map[string][]string) ([]*ent.Decision, error) { |
| 28 | // Do not select all fields. |
| 29 | // This can get pretty expensive network-wise if there are a lot of decisions and you are using a remote database |
| 30 | query := c.Ent.Decision.Query(). |
| 31 | Select(decision.FieldID, decision.FieldUntil, decision.FieldScenario, decision.FieldScope, decision.FieldValue, decision.FieldType, decision.FieldOrigin, decision.FieldUUID). |
| 32 | Where( |
| 33 | decision.UntilGT(now), |
| 34 | ) |
| 35 | // Allow a bouncer to ask for non-deduplicated results |
| 36 | if v, ok := filter["dedup"]; !ok || v[0] != "false" { |
| 37 | query = query.Where(longestDecisionForScopeTypeValue) |
| 38 | } |
| 39 | |
| 40 | query, err := applyDecisionFilter(query, filter) |
| 41 | if err != nil { |
| 42 | c.Log.Warningf("QueryAllDecisionsWithFilters : %s", err) |
| 43 | return []*ent.Decision{}, fmt.Errorf("get all decisions with filters: %w", QueryFail) |
| 44 | } |
| 45 | |
| 46 | query = query.Order(ent.Asc(decision.FieldID)) |
| 47 | |
| 48 | data, err := query.All(ctx) |
| 49 | if err != nil { |
| 50 | c.Log.Warningf("QueryAllDecisionsWithFilters : %s", err) |
| 51 | return []*ent.Decision{}, fmt.Errorf("get all decisions with filters: %w", QueryFail) |
| 52 | } |
| 53 | |
| 54 | return data, nil |
| 55 | } |
| 56 | |
| 57 | func (c *Client) QueryExpiredDecisionsWithFilters(ctx context.Context, now time.Time, filter map[string][]string) ([]*ent.Decision, error) { |
| 58 | query := c.Ent.Decision.Query(). |