Log inBook a Demo
OptimizeMidBackendAuto-graded

Kill the per-post queries in a /feed endpoint

Checks whether one of the most common causes of slow pages is recognized and removed without changing what users see.The /feed endpoint is slow under load. It loads every post and then, for each one, fires a query for the author and another for the comment count — about 1001 queries for 500 posts. That is the textbook N+1. Rewrite build_feed() so it returns exactly the same feed using a small, constant number of queries however many posts there are. No database to install; the module counts queries for you.
30 min
python

You're done when

  • The number of queries is small and does not grow with the number of posts.
  • Lookups are batched rather than issued per post.

What it measures

Performance optimizationRemoving per-item queries by batching, and confirming the win by counting queries rather than guessing.
Database administrationRestructuring access so the query count is bounded by the shape of the code, not by the size of the data.
Refactoring without regressionChanging how data is fetched while keeping output byte-identical, which is what makes the optimisation safe to ship.

Your environment

Terminal + editorA full shell in the browser
Claude CodePre-authenticated, no key setup
Isolated microVMYours alone, wiped afterwards

Start this lab

30 min
Start labYou'll sign in to Anthropos to start. The lab opens in a private cloud workspace with Claude Code ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo