Skip to content

Conversation

@laurenceisla
Copy link
Member

Closes #3957

@laurenceisla laurenceisla changed the title fix(wip): optimize count=exact when there's no limits, offsets or db-max-rows perf(wip): optimize count=exact when there's no limits, offsets or db-max-rows Dec 20, 2025
@laurenceisla laurenceisla marked this pull request as ready for review December 23, 2025 02:47
@steve-chavez
Copy link
Member

@laurenceisla Could you inline all the context here? 🙏 I'm finding difficult to understand the PR.

@laurenceisla
Copy link
Member Author

@steve-chavez Yes, so the requests handle two counts when using the Prefer: count=exact header in the request. This is to build the two parts of the Content-Range header. For example, let's take our items table:

$ curl 'localhost:3000/items?limit=5' -H 'Prefer: count=exact' -I
HTTP/1.1 206 Partial Content
...
Content-Range: 0-4/15

To build the Content-Range, It counts the limited query to get the 0-4 and the total query to get the 15 (two counts in total).

However if there's nothing that would limit the request (limit, offset or db-max-rows) then we'd get:

$ curl 'localhost:3000/items' -H 'Prefer: count=exact' -I
HTTP/1.1 200 OK
...
Content-Range: 0-14/15

The total quantity would always be the same for both parts of the Content-Range: 0-14 and 15 (15 items for both). So, this PR only counts once (the 0-14 part) and uses the same result to build the second part of the Content-Range (the 15 part).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Prefer: count=exact optimization on HEAD request

2 participants