Performance: Server action database mutations
MEDIUM IMPACT
This affects the time to update data on the server and how quickly the UI reflects those changes, impacting interaction responsiveness and perceived speed.
let dbConnection; export async function updateUser(data) { if (!dbConnection) { dbConnection = await db.connect(); } await db.users.updateOne({ id: data.id }, { $set: data }); // Keep connection open for batch mutations } // Debounce input to reduce calls
export async function updateUser(data) { await db.connect(); await db.users.updateOne({ id: data.id }, { $set: data }); await db.disconnect(); } // Called on every user input change triggering multiple server actions rapidly
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Connect/disconnect DB per mutation | N/A | N/A | Blocks UI update 200-500ms | [X] Bad |
| Reuse DB connection and batch mutations | N/A | N/A | Blocks UI update <50ms | [OK] Good |