Zum Inhalt springen

Write Inside Loop (ARCH6052)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key ruby.orm.write-inside-loop · Severity warning · Category orm

Calling save/commit on every loop iteration produces one DB round-trip per item. That means N round-trips instead of a single batch operation.

names.each do |name|
User.create!(name: name) # a separate INSERT per iteration
end
records = names.map { |name| { name: name } }
User.insert_all(records) # one bulk INSERT

Accumulate the records and write them once with a bulk API like insert_all instead of persisting per row.