-
-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api): Add 'count' parameter to return total item count in API v4 #4715
Conversation
- When `count=on` is specified in a paginated list endpoint query params, the API returns only the total count of items matching the query - In standard v4 paginated responses, include a `count` key with a URL to get the total count - This feature helps users verify if their filters are working by easily accessing the total count
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice!
One thought that might be helpful is to confirm the number and type of queries via a test. Could you add that?
The rest looks great to me, if it looks good to other folks.
Process notes:
Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good to me.
I just left a couple of minor comments.
I also agree with Mike's suggestion to add or tweak the current tests to verify the number and type of queries performed during a regular request and a count request. To ensure that no count query is executed during regular requests, and only the count query is executed during count requests. I think you can base on ApiQueryCountTests
Thank you!
Co-authored-by: Alberto Islas <[email protected]>
for more information, see https://pre-commit.ci
Co-authored-by: Alberto Islas <[email protected]>
Co-authored-by: Alberto Islas <[email protected]>
That makes sense, so from now on I'll just add you as a reviewer once a PR is ready for review, and I'll add it to the current sprint 🫡 |
Thank you @albertisfu and @mlissner for the comments! I'm working on the tests and I think the class you mentioned ( |
Yeah, I agree. that's a good place to add the new tests! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @elisa-a-v the changes and the API count tests added look great.
We can merge this one @mlissner
Resolves #4506
This PR introduces a new
count=on
query parameter to our paginated API endpoints. When this parameter is included in a request, the API returns only the total count of items matching the query filters, without including any result data.If no
count=on
is added to the request, a count key is now included in the response just like in v3, but instead of providing the count immediately, it provides a URL that points to the count endpoint for the current query parameters to guide users on how to obtain the total count if needed.V4 removed the count due to the overhead of counting huge querysets in each request, which is why we're adding this tweaked version of the count in the response so the users have access to the information if needed without reintroducing the overhead.
Also updated docs to reflect these changes: