MCPcopy
hub / github.com/crowdsecurity/crowdsec / ExpireDecisions

Method ExpireDecisions

pkg/database/decisions.go:328–346  ·  view source on GitHub ↗

ExpireDecisions sets the expiration of a list of decisions to now(), in multiple operations if len(decisions) > decisionDeleteBulkSize. It returns the number of impacted decisions for the CAPI/PAPI, even in case of error.

(ctx context.Context, decisions []*ent.Decision)

Source from the content-addressed store, hash-verified

326// in multiple operations if len(decisions) > decisionDeleteBulkSize.
327// It returns the number of impacted decisions for the CAPI/PAPI, even in case of error.
328func (c *Client) ExpireDecisions(ctx context.Context, decisions []*ent.Decision) (int, error) {
329 if len(decisions) == 0 {
330 return 0, nil
331 }
332
333 now := time.Now().UTC()
334
335 total := 0
336 err := slicetools.Batch(ctx, decisions, decisionDeleteBulkSize, func(ctx context.Context, batch []*ent.Decision) error {
337 rows, err := c.expireDecisionBatch(ctx, batch, now)
338 if err != nil {
339 return err
340 }
341 total += rows
342 return nil
343 })
344
345 return total, err
346}
347
348// deleteDecisionBatch removes the decisions as a single operation.
349func (c *Client) deleteDecisionBatch(ctx context.Context, batch []*ent.Decision) (int, error) {

Callers 2

ExpireDecisionByIDMethod · 0.95

Calls 1

expireDecisionBatchMethod · 0.95

Tested by

no test coverage detected