Loading…
Loading…
Main had a simple stub that just returned an array of orders by id. A colleague sent a PR enriching them with user and product data. In tests (3 orders) it runs in 100 ms; in production the endpoint takes 8 seconds. Walk the diff and find every N+1.
N+1 is the classic data-access problem: instead of 1 query to the DB, you make N+1, where N is the collection size. Typical example: fetched the list of orders (1 query), then a separate user query for every order (N queries). Total — N+1. Sign in code: `await` inside `for` or `forEach` over an array, where a related resource is fetched. Find every N+1 in the PR — there are three.