Practice ยท 3 of 3
N+1 Refactor
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.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: API โ Database โ Practice