Skip to content

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
Contributor

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

@lovelydinosaur
Copy link
Contributor

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

@lovelydinosaur lovelydinosaur merged commit a7e2a7b into encode:master Mar 23, 2018
@lovelydinosaur
Copy link
Contributor

👍

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
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.

3 participants