# Fix an N+1 in one endpoint or resolver

One endpoint issuing a query per row, fixed with a query-count test that fails against the old code.

Category: Data layer and migrations
Source: https://letsship.ai/use-cases/fix-an-n-plus-one
Published: 2026-08-25

## Goal

Remove the N+1 query pattern from one endpoint or resolver.

## Acceptance criteria

- A test asserts the number of queries issued
- That test fails against the current code
- Results are identical before and after
- The fix batches or joins rather than caching over the top

## What lands as proof

A query-count assertion, which is the only test that actually catches an N+1 coming back.

## Prompt

Copy this to an agent to open the ticket:

```text
Create a Linear issue in my team and assign it to the SHIP agent.

Title: Fix the N+1 in {endpoint}

Description: Remove the N+1 query pattern from one endpoint or resolver.

Acceptance criteria:
- A test asserts the number of queries issued
- That test fails against the current code
- Results are identical before and after
- The fix batches or joins rather than caching over the top

Before you create the issue, enable query logging in this repository and find an endpoint issuing one query per row. Replace {endpoint}.
```

## Questions

### What does the agent actually change?

The ticket is scoped to one outcome: remove the N+1 query pattern from one endpoint or resolver. Work that serves that outcome is in scope, and anything outside it is left for a separate ticket, so the pull request stays reviewable.

### How do I know the work is done?

The pull request carries the evidence, not only the diff. Here that means query-count test that fails against the old code, so a reviewer can confirm the result without reproducing the work locally.

### How much oversight does this need?

None is required before the run starts. Every claim this ticket makes can be checked by machine, so the agent works straight through and a person reviews the finished pull request like any other.
