Performance: Relations (OneToMany, ManyToOne, ManyToMany)
MEDIUM IMPACT
This affects database query performance and server response time, impacting how fast data loads and updates in the app.
const users = await userRepository.find({ relations: ['posts'] });
const users = await userRepository.find(); for (const user of users) { user.posts = await postRepository.find({ where: { user: { id: user.id } } }); }
| Pattern | Database Queries | Query Count | Response Time Impact | Verdict |
|---|---|---|---|---|
| N+1 Query Pattern | Multiple separate queries | N+1 queries | High response time, slower LCP | [X] Bad |
| Eager Loading Relations | Single joined query | 1 query | Low response time, faster LCP | [OK] Good |
| ManyToMany without indexes | Join queries on large tables | 1 query | Potentially slow if unindexed | [!] OK |
| ManyToMany with indexed join table | Optimized join query | 1 query | Fast response, scalable | [OK] Good |