Menu

1 / 4

Your Agent's Endpoint Runs 101 Queries. A Query-Count Test Fails the Branch First

DEV Community: postgres·Gabriel Anhaia·7 days ago
#uTDzIxMW
#devtopostgresql#devto#dev#test#query
Reading 0:00
15s threshold

Book: Database Playbook

Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

A page of 100 orders, 101 round trips to Postgres , and every test on the agent's branch is green.

The agent's GET /orders handler returns each order with its customer's name. It fetches the orders, then loops over them and fetches each customer with its own query: one for the list, one per row. The diff is short and readable, and the test data has two rows.

That is the N+1 query problem. The Laravel docs put numbers on it: 25 books and their authors, loaded in a loop, "would run 26 queries". Your functional tests don't catch it. They check the JSON, and the JSON is correct. None of them counts the queries behind it.

So you add a test that does.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.