mirror of
https://github.com/fleetdm/fleet
synced 2026-05-20 07:29:08 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #37244 # Checklist for submitter If some of the following don't apply, delete the relevant line. - [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/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Internal MySQL utility package reorganized and all internal imports updated to the new platform location; no changes to end-user functionality or behavior. * **Documentation** * Added platform package documentation describing infrastructure responsibilities and architectural boundaries to guide maintainers. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
26 lines
633 B
Go
26 lines
633 B
Go
package 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
|
|
}
|