25 lines
384 B
Go
25 lines
384 B
Go
package actions
|
|
|
|
import (
|
|
"zzman/model"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func RecordChange(tx *gorm.DB, changes []model.Change) error {
|
|
if len(changes) == 0 {
|
|
return nil
|
|
}
|
|
|
|
batchSize := 1000
|
|
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
|
|
}
|