Files
jh-zz/actions/changes.go

25 lines
384 B
Go
Raw Permalink Normal View History

package actions
import (
"jhman/model"
"gorm.io/gorm"
)
2025-09-10 18:26:59 +08:00
func RecordChanges(tx *gorm.DB, changes []model.Change) error {
if len(changes) == 0 {
return nil
}
2025-09-10 18:26:59 +08:00
batchSize := 500
for i := 0; i < len(changes); i += batchSize {
end := min(i+batchSize, len(changes))
batch := changes[i:end]
err := tx.Create(&batch).Error
if err != nil {
return err
}
}
return nil
}