PR REVIEWHeavy Computation Blocking the Event Loop#112ShopifyVercel
00:00Mid~12 min
PULL REQUEST
Open#112 · 1 commit
Heavy Computation Blocking the Event Loop
mid-dev-44 wants to mergefeat/admin-csv-exportmain
MI
mid-dev-44
1 file changed · 2 hours ago
YOUR MISSION
A new feature allows admins to download an audit log of 100,000+ records. The file generates successfully, but while it is downloading, the entire Node.js server becomes completely unresponsive to all other users for 3–5 seconds.
Mid~12 min
HINTS (0/3 used)
REVIEWING AS
SR
Senior Engineer
@ Shopify · Backend Platform
src / routes / admin.ts+8 0
10
10
router.get("/export/logs", requireAdmin, async (req, res) => {
11
11
// Fetch 100,000+ logs
12
12
const logs = await db.query("SELECT * FROM audit_logs");
13
13
14
+
// Format as CSV
+
15
+
const csvHeader = "id,action,user_id,created_at\n";
+
16
+
const csvRows = logs.rows.map(log =>
+
17
+
`${log.id},${log.action},${log.user_id},${log.created_at}`
+
18
+
).join("\n");
+
19
+
+
20
+
res.header("Content-Type", "text/csv");
+
21
+
res.send(csvHeader + csvRows);
+
14
22
});
Click any changed line (+/−) to flag an issue · or Approve if everything looks safe