python - Improving pagination and serialization time in django rest framework -
i using listapiview
render list of objects. response returns paginated results limit=50
. queryset size varies 0 few hundred thousands.
what have noticed when queryset size small, api response time small. queryset size increases, api response time becomes large.
is pagination culprit here?
there way optimize response time listapiview
s using pagination?
as stated in official django documentation, querysets lazy.
querysets lazy – act of creating queryset doesn’t involve database activity. can stack filters day long, , django won’t run query until queryset evaluated.
also, pagination compliments queryset's laziness.
therefore, culprit delay not pagination.
case closed...
but then?
- processing queryset before pagination. hits database multiple times, slowing app down.
ordering
@sha256 suggests.- very costly queries perhaps (you can check following docs).
what faster?
Comments
Post a Comment