Zum Inhalt springen

Write Inside Loop (ARCH3052)

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

Key typescript.orm.write-inside-loop · Severity error · Category orm

Calling save/commit/flush on every loop iteration causes one database round-trip per item. Accumulate the changes and persist them once.

for (const dto of items) {
const entity = repo.create(dto);
await repo.save(entity); // a round-trip per iteration
}
const entities = items.map(dto => repo.create(dto));
await repo.save(entities); // one batched write

Move the persistence call out of the loop and save the collection in a single call.