Skip to content
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

Add LimitOffsetPagination.get_count to allow method override #5846

Merged
merged 2 commits into from Mar 23, 2018

Conversation

chukkwagon
Copy link
Contributor

@chukkwagon chukkwagon commented Feb 22, 2018

Description

This PR:

  • removes pagination._get_count
  • adds LimitOffsetPagination.get_count instance method
  • modifies LimitOffsetPagination.paginate_queryset

I have a custom pagination class that subclasses LimitOffsetPagination. When paginating a large queryset with an .order_by() clause, the combination of sorting can add a lot of overhead to the pagination calculation, which in turn slows down the entire response. Adding get_count() as an instance method gives developers the ability to override it's behavior if necessary. In my case, I will override the method to remove any ordering constraints from the queryset.

def get_count(self, queryset):
"""
Determine an object count, supporting either querysets or regular lists.
"""
Copy link
Member

@rpkilby rpkilby Feb 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring spacing should be fixed

@tomchristie
Copy link
Member

tomchristie commented Feb 23, 2018

Yup I'm okay with this, pending @rpkilby's suggested changes.

@tomchristie tomchristie merged commit a7e2a7b into encode:master Mar 23, 2018
1 check passed
@tomchristie
Copy link
Member

tomchristie commented Mar 23, 2018

👍

pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this issue Nov 17, 2020
…5846)

* Add LimitOffsetPagination.get_count to allow method override

* Format method docstring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants