Write Inside Loop (ARCH5052)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key go.orm.write-inside-loop · Severity error · Category orm
Issuing a separate Create/Save on every loop iteration means one DB round-trip per item. Use a batch write instead.
Incorrect
Section titled “Incorrect”for _, u := range users { db.Create(&u) // separate INSERT per iteration}Correct
Section titled “Correct”db.CreateInBatches(users, 100)Collapse per-iteration persist calls into a single batch write such as CreateInBatches.