Performance: Database query optimization
This affects how fast data loads on the page and how responsive the app feels when fetching data.
const user = await db.query('SELECT id, name, email FROM users WHERE id = ?', [userId]);
const user = await db.query('SELECT * FROM users');
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fetching all data without filters | Minimal DOM nodes initially | Delays reflow due to slow data | High paint delay waiting for data | [X] Bad |
| Fetching only needed fields with filters | Minimal DOM nodes | Single reflow after data arrives | Paint happens quickly after data | [OK] Good |
| N+1 queries for related data | Multiple DOM updates as data arrives | Multiple reflows triggered | Paint delayed by multiple queries | [X] Bad |
| Single optimized query with joins | Single DOM update | Single reflow | Fast paint after data | [OK] Good |
const posts = await prisma.post.findMany({ where: { published: true }, orderBy: { createdAt: 'desc' }, take: 5 });const users = await prisma.user.findMany({ where: { age: { gt: 18 } }, limit: 10 });Pass the test and this pattern moves unknown