Performance: Transaction handling
MEDIUM IMPACT
This affects the responsiveness and throughput of backend operations that modify data, impacting how fast users see updates and how well the server handles concurrent requests.
async function updateUserData(db, userId, data) { const client = await db.connect(); try { await client.query('BEGIN'); await client.query('UPDATE users SET name = $1 WHERE id = $2', [data.name, userId]); await client.query('UPDATE profiles SET bio = $1 WHERE user_id = $2', [data.bio, userId]); await client.query('COMMIT'); } catch (e) { await client.query('ROLLBACK'); throw e; } finally { client.release(); } }
async function updateUserData(db, userId, data) { await db.query('BEGIN'); await db.query(`UPDATE users SET name = '${data.name}' WHERE id = ${userId}`); await db.query(`UPDATE profiles SET bio = '${data.bio}' WHERE user_id = ${userId}`); await db.query('COMMIT'); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous blocking transaction | 0 | 0 | 0 | [X] Bad |
| Asynchronous parameterized transaction with connection pooling | 0 | 0 | 0 | [OK] Good |