diff --git a/finisher_api.go b/finisher_api.go index 2d7409c7..bef65ae5 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -35,10 +35,12 @@ func (db *DB) CreateInBatches(value interface{}, batchSize int) (tx *DB) { tx = db.getInstance() callFc := func(tx *DB) error { - for i := 0; i < reflectValue.Len(); i += batchSize { + // the reflection length judgment of the optimized value + reflectLen := reflectValue.Len() + for i := 0; i < reflectLen; i += batchSize { ends := i + batchSize - if ends > reflectValue.Len() { - ends = reflectValue.Len() + if ends > reflectLen { + ends = reflectLen } subtx := tx.getInstance()