简体   繁体   中英

Improving pagination and serialization time in django rest framework

I am using ListAPIView to render a list of objects. The response returns paginated results with limit=50 . The queryset size varies from 0 to a few hundred thousands.

What I have noticed is that when the queryset size is small, the API response time is small. But as the queryset size increases, the API response time becomes very large.

Is pagination actually the culprit here?
Is there a way to optimize the response time for ListAPIView s using pagination?

As stated in the official django documentation, querysets are lazy .

QuerySets are lazy – the act of creating a QuerySet doesn't involve any database activity. You can stack filters together all day long, and Django won't actually run the query until the QuerySet is evaluated.

Also, pagination compliments queryset's laziness .

Therefore, the culprit for your delay IS NOT pagination.
Case closed...


But what is it then?

What to do to get faster?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM