@@ -14,6 +14,7 @@ import (
1414	log "github.com/sirupsen/logrus" 
1515
1616	"github.com/crowdsecurity/go-cs-lib/cstime" 
17+ 	"github.com/crowdsecurity/go-cs-lib/slicetools" 
1718
1819	"github.com/crowdsecurity/crowdsec/pkg/csnet" 
1920	"github.com/crowdsecurity/crowdsec/pkg/database/ent" 
@@ -168,7 +169,7 @@ func (c *Client) CreateOrUpdateAlert(ctx context.Context, machineID string, aler
168169	// create missing decisions in batches 
169170
170171	decisions  :=  make ([]* ent.Decision , 0 , len (decisionBuilders ))
171- 	if  err  :=  Batch (ctx , decisionBuilders , c .decisionBulkSize , func (ctx  context.Context , b  []* ent.DecisionCreate ) error  {
172+ 	if  err  :=  slicetools . Batch (ctx , decisionBuilders , c .decisionBulkSize , func (ctx  context.Context , b  []* ent.DecisionCreate ) error  {
172173		ret , err  :=  c .Ent .Decision .CreateBulk (b ... ).Save (ctx )
173174		if  err  !=  nil  {
174175			return  fmt .Errorf ("creating alert decisions: %w" , err )
@@ -181,7 +182,7 @@ func (c *Client) CreateOrUpdateAlert(ctx context.Context, machineID string, aler
181182
182183	// attach decisions to alert in batches 
183184
184- 	if  err  :=  Batch (ctx , decisions , c .decisionBulkSize , func (ctx  context.Context , d  []* ent.Decision ) error  {
185+ 	if  err  :=  slicetools . Batch (ctx , decisions , c .decisionBulkSize , func (ctx  context.Context , d  []* ent.Decision ) error  {
185186		if  err  :=  c .Ent .Alert .Update ().Where (alert .UUID (alertItem .UUID )).AddDecisions (d ... ).Exec (ctx ); err  !=  nil  {
186187			return  fmt .Errorf ("updating alert %s: %w" , alertItem .UUID , err )
187188		}
@@ -333,7 +334,7 @@ func (c *Client) UpdateCommunityBlocklist(ctx context.Context, alertItem *models
333334
334335	// Delete older decisions from capi 
335336
336- 	if  err  :=  Batch (ctx , valueList , c .decisionBulkSize , func (ctx  context.Context , vals  []string ) error  {
337+ 	if  err  :=  slicetools . Batch (ctx , valueList , c .decisionBulkSize , func (ctx  context.Context , vals  []string ) error  {
337338		deletedDecisions , err  :=  txClient .Decision .Delete ().
338339			Where (decision .And (
339340				decision .OriginEQ (decOrigin ),
@@ -351,7 +352,7 @@ func (c *Client) UpdateCommunityBlocklist(ctx context.Context, alertItem *models
351352
352353	// Insert new decisions 
353354
354- 	if  err  :=  Batch (ctx , decisionBuilders , c .decisionBulkSize , func (ctx  context.Context , b  []* ent.DecisionCreate ) error  {
355+ 	if  err  :=  slicetools . Batch (ctx , decisionBuilders , c .decisionBulkSize , func (ctx  context.Context , b  []* ent.DecisionCreate ) error  {
355356		insertedDecisions , err  :=  txClient .Decision .CreateBulk (b ... ).Save (ctx )
356357		if  err  !=  nil  {
357358			return  err 
@@ -549,7 +550,7 @@ func buildMetaCreates(ctx context.Context, logger log.FieldLogger, client *ent.C
549550
550551func  buildDecisions (ctx  context.Context , logger  log.FieldLogger , client  * Client , alertItem  * models.Alert , stopAtTime  time.Time ) ([]* ent.Decision , int , error ) {
551552	decisions  :=  []* ent.Decision {}
552- 	if  err  :=  Batch (ctx , alertItem .Decisions , client .decisionBulkSize , func (ctx  context.Context , part  []* models.Decision ) error  {
553+ 	if  err  :=  slicetools . Batch (ctx , alertItem .Decisions , client .decisionBulkSize , func (ctx  context.Context , part  []* models.Decision ) error  {
553554		ret , err  :=  client .createDecisionBatch (ctx , * alertItem .Simulated , stopAtTime , part )
554555		if  err  !=  nil  {
555556			return  fmt .Errorf ("creating alert decisions: %w" , err )
@@ -625,7 +626,7 @@ func saveAlerts(ctx context.Context, c *Client, batch []alertCreatePlan) ([]stri
625626			continue 
626627		}
627628
628- 		if  err  :=  Batch (ctx , d , c .decisionBulkSize , func (ctx  context.Context , d2  []* ent.Decision ) error  {
629+ 		if  err  :=  slicetools . Batch (ctx , d , c .decisionBulkSize , func (ctx  context.Context , d2  []* ent.Decision ) error  {
629630			return  retryOnBusy (func () error  {
630631				_ , err  :=  c .Ent .Alert .Update ().Where (alert .IDEQ (a .ID )).AddDecisions (d2 ... ).Save (ctx )
631632				return  err 
@@ -744,7 +745,7 @@ func (c *Client) CreateAlert(ctx context.Context, machineID string, alertList []
744745	c .Log .Debugf ("writing %d items" , len (alertList ))
745746
746747	alertIDs  :=  []string {}
747- 	if  err  :=  Batch (ctx , alertList , alertCreateBulkSize , func (ctx  context.Context , part  []* models.Alert ) error  {
748+ 	if  err  :=  slicetools . Batch (ctx , alertList , alertCreateBulkSize , func (ctx  context.Context , part  []* models.Alert ) error  {
748749		ids , err  :=  c .createAlertBatch (ctx , machineID , owner , part )
749750		if  err  !=  nil  {
750751			return  fmt .Errorf ("machine %q: %w" , machineID , err )
0 commit comments