知识卡片
限制总量不同于分页
数据集持续增长时,无界查询返回会拖慢接口及其依赖服务。
数据接口应有默认最大返回量,检查调用方提供的值,并优先把限制传到存储查询。只在接口拿到完整结果后截断,虽然减少对外载荷,却无法避免上游查询、传输和内存代价。
总量限制决定本次查询最多选取多少条,分页大小决定每次展示其中多少条;例如总限1000、每页100,不是只查100条。修改限制或截断结果后,应在元数据中说明实际返回数、总量估计与截断状态。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 分布式数据 · 查看原书依据
Using the truncated limit approach has its drawbacks. For example, you do not get to control how large a data set may be returned to you from the underlying data source. Even if your API limits response collections to 100 records, you may still need to wait for the underlying (unlimited) data source to search for and return 100,000 records before you can implement your internal truncation routine.
参考来源
- 位置:《RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)》第6章《分布式数据》§6.12(来源项目:book-sources;源文件:extracted/RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)/_epub-src/OEBPS/ch06.xhtml)
- 结论依据:原文以数据接口应有默认最大返回量,检查调用方提供的值,并优先把限制传到存储查询的方式说明该用途;同节示例与讨论补充了卡内条件和边界。
- 原始内容:Using the truncated limit approach has its drawbacks. For example, you do not get to control how large a data set may be returned to you from the underlying data source. Even if your API limits response collections to 100 records, you may still need to wait for the underlying (unlimited) data source to search for and return 100,000 records before you can implement your internal truncation routine.