-
Notifications
You must be signed in to change notification settings - Fork 766
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
Avoid calling count unless it is required #177
Comments
You may find that https://github.com/photocrowd/django-cursor-pagination helps here, I wrote it to do "true" cursor style pagination, and have a version of |
@mjtamlyn how would django cursor pagination help? I am missing something here, could you provide an example on how to use it? |
The current version of Connection paginates using the index within the list you're currently at, and calculates the total count to evaluate whether there is another page after the current one. Cursor pagination identifies ordering data from the field, and loads "the first n after the ordering value x". By loading n+1 items, you know whether there is at least one item afterwards, but you have no idea whether there is 1 or 10000. This style of query is also much more efficient for the database when loading much later pages. |
To clarify here, that pagination library is good, but currently It would probably be possible, but it would require a lot of hacks and would likely be very brittle to upgrades in the library. I suggest that we wait for customisable pagination support. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Here is the alternate
|
If relay doesn't require a length to create a slice like proposed at graphql-python/graphql-relay-py#16 a fix for graphene-django would be easy. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
What is the official solution here? |
@mjtamlyn Any chance you could make your version of DjangoConnectionField that uses django-cursor-pagination public? I'm in a similar situation and it would be super useful. |
It's in the gist linked from the comment above: https://gist.github.com/crucialfelix/d14506cdb9d3a04427a72aadcad30af4 |
@crucialfelix forgive me if I'm mistaken but that looks like it uses offset based pagination? |
Yes it does— the same way as the original DjangoConnectField does. For relay the offset is encoded in the after hash: |
@crucialfelix mjtamlyn had mentioned they have a version of DjangoConnecionField true cursor based pagination, as opposed to offset based. That's what I was interested in. |
@crucialfelix how do you go about using |
It is checking the count for every query, but isn't using it for anything AFAICT except
hasNextPage
DjangoObjectType
andDjangoConnectionField
This is a massive performance hit on postgresql. If I am selecting only 10 items and I don't ask for the count then it should not call count. Even if the number of records is < 10 it still calls count.
For hasNextPage you can just iterate one past.
Related to #162 - it would be nice to get totalCount when we need it, but only pay the performance price then.
The text was updated successfully, but these errors were encountered: