Skip to main content

Practice ยท 1 of 2

Detect N+1 from the query log

Implement count_queries(request_log) โ€” request_log is a list of (request_id, queries) where queries is a list of strings: - 'fetch-all:<entity>' queries load a collection - 'fetch-one:<entity>:<id>' queries load one entity in a loop - return (total, offenders): total counts every query; offenders lists request_ids (first-seen order) with the N+1 signature โ€” a fetch-all followed by **3 or more** fetch-one queries A request with many queries but no fetch-all-then-loop pattern is NOT an offender (batch jobs do big legitimate work).

Difficulty: advanced

Back to lesson: Practice: Data Service Mini-Project