Skip to main content

Practice · 3 of 3

N+1 Refactor

CHALLENGE
Difficulty: intermediate+25 XP

Write countFetches(taskCount, strategy) — strategy "naive" => 1 + taskCount queries; "join" => 1; "batch" => 2. Then refactorReport(taskCount, savedMs) — compute naive vs join query counts and estimate time saved as (naive - join) * savedMs; return { naive, join, msSaved }. This is the arithmetic that convinces teams to fix N+1.

Back to lesson: Practice: API ↔ Database — Practice