fleet/server/datastore/mysql/common_mysql/batch.go
Victor Lyuboslavsky 7e1a808a8c
Fixing issue where deleted profiles were being sent to devices. (#25095)
#24804 

# Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files)
for more information.
- [x] Added/updated tests
- [x] If database migrations are included, checked table schema to
confirm autoupdate
- [x] Manual QA for all new/changed functionality
2025-01-06 13:16:34 -06:00

26 lines
640 B
Go

package common_mysql
// BatchProcessSimple is a simple utility function to batch process a slice of payloads.
// Provide a slice of payloads, a batch size, and a function to execute on each batch.
func BatchProcessSimple[T any](
payloads []T,
batchSize int,
executeBatch func(payloadsInThisBatch []T) error,
) error {
if len(payloads) == 0 || batchSize <= 0 || executeBatch == nil {
return nil
}
for i := 0; i < len(payloads); i += batchSize {
start := i
end := i + batchSize
if end > len(payloads) {
end = len(payloads)
}
if err := executeBatch(payloads[start:end]); err != nil {
return err
}
}
return nil
}