diff --git a/cmd/sync/aws.go b/cmd/sync/aws.go index 42e9ad4a..77d8516d 100644 --- a/cmd/sync/aws.go +++ b/cmd/sync/aws.go @@ -225,18 +225,17 @@ func (client *AWSClient) getInstancesInService(insIDtoIP map[string]string) ([]s } func prepareBatches(maxItems int, items []string) [][]string { - var batches [][]string + totalBatches := (len(items) + maxItems - 1) / maxItems + batches := make([][]string, 0, totalBatches) - min := func(a, b int) int { - if a <= b { - return a + for i := 0; i < len(items); i += maxItems { + end := i + maxItems + if end > len(items) { + end = len(items) } - return b + batches = append(batches, items[i:end]) } - for i := 0; i < len(items); i += maxItems { - batches = append(batches, items[i:min(i+maxItems, len(items))]) - } return batches }