Write Inside Loop (ARCH3052)
Esta página aún no está disponible en tu idioma.
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.
Incorrect
Section titled “Incorrect”for (const dto of items) { const entity = repo.create(dto); await repo.save(entity); // a round-trip per iteration}Correct
Section titled “Correct”const entities = items.map(dto => repo.create(dto));await repo.save(entities); // one batched writeMove the persistence call out of the loop and save the collection in a single call.