Skip to content

Add LimitOffsetPagination.get_count to allow method override #5846

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Mar 23, 2018

Conversation

chukkwagon
Copy link
Contributor

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

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

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

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

👍

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

* Add LimitOffsetPagination.get_count to allow method override

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

Successfully merging this pull request may close these issues.

3 participants