chore: explain number record each batch more clear

main
sudo pacman -Syu 2022-11-07 00:16:36 +07:00
parent 85eede5e8b
commit 46545e1762
No known key found for this signature in database
GPG Key ID: D6CB5C6C567C47B0
1 changed files with 8 additions and 0 deletions

View File

@ -147,6 +147,13 @@ func (p *populator) InsertBatch(ctx context.Context, tableName string, numberRec
return fmt.Errorf("maximum question marks [%d]: %w", len(questionMarks), ErrMaximumQuestionMarks)
}
// Because the numberRecordLastBatch may less than numberRecordEachBatch
// For example
// numberRecord := 120
// numberRecordEachBatch := 50
// numberBatch := 120/50 + 1 = 3
// First 2 batches => 50 * 2 = 100
// Last batch => 120 - 100 = 20
numberBatch := numberRecord/numberRecordEachBatch + 1
numberRecordLastBatch := numberRecord - (numberBatch-1)*numberRecordEachBatch
@ -154,6 +161,7 @@ func (p *populator) InsertBatch(ctx context.Context, tableName string, numberRec
valuesQuestionMarks := make([]string, 0, tempNumberRecord)
argsInsert := make([]any, 0, tempNumberRecord*len(argFns))
for i := 0; i < tempNumberRecord; i++ {
// (?, ?, ?)
valuesQuestionMarks = append(valuesQuestionMarks, fmt.Sprintf("(%s)", strings.Join(questionMarks, ", ")))
// Generate each time insert for different value