改进Django-rest-fram中的分页和序列化时间

2024-09-29 21:34:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用ListAPIView来呈现对象列表。响应返回带limit=50的分页结果。查询集大小从0到几十万不等。在

我注意到的是,当queryset很小时,API响应时间很短。但是随着queryset大小的增加,API响应时间变得非常大。在

分页真的是罪魁祸首吗?
有没有一种方法可以使用分页优化ListAPIViews的响应时间?在


Tags: 对象方法api列表时间querysetlimit小时
1条回答
网友
1楼 · 发布于 2024-09-29 21:34:37

如django官方文档所述,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.

还有,pagination compliments queryset's laziness。在

因此,延迟的culprit不是分页。
结案。。。在


但那又是什么呢?在

怎样才能更快?在

相关问题 更多 >

    热门问题