1 min read
Keeping Django endpoints at a fixed query count (Sample post)
A sample post: pinning the number of SQL queries per endpoint in tests so a list never slows down as content grows.
This is a sample post created by seed_mock. Replace or delete it in Admin.
Why a budget
Every endpoint should cost the same number of queries whether it returns three rows or three hundred. A test makes that promise explicit.
def test_list_budget(api, django_assert_num_queries):
with django_assert_num_queries(2):
api.get("/api/v1/projects/")
| Endpoint | Queries |
|---|---|
| List | 2 |
| Detail | 4 |