N Plus One Query (ARCH3050)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key typescript.orm.n-plus-one-query · Severity warning · Category orm
Running a separate query for each element inside a loop produces one list query plus N follow-up queries. This is the classic ORM performance killer; fetch related data in a single round-trip.
Incorrect
Section titled “Incorrect”const orders = await orderRepo.find();for (const order of orders) { // A separate SELECT per order const customer = await customerRepo.findOneBy({ id: order.customerId }); console.log(customer.name);}Correct
Section titled “Correct”const orders = await orderRepo.find({ relations: { customer: true } });for (const order of orders) { console.log(order.customer.name);}Eager-load related data with relations/include and drop the per-iteration queries.