← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 1971.o.1.b.4.d.1.c.4.a.3.a.2

汇总查询避免装载所有实体

理解等级:中级

仓储接口隐藏存储机制,调用方开发者仍须了解查询的代价。原书的制造业应用在生产环境为汇总信息调用“所有对象”,先把全库实体实例化再取少数属性,数小时后内存耗尽;小测试数据未暴露问题。需要计数或求和时,应考虑让仓储直接返回相应汇总,而非先加载每个实体。此为原书转述的项目事件,不是对所有仓储实现的实测结论。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 原书第06章|Repositories · 查看原书依据

      The developers had done this using a query called "all objects," which instantiated each of the objects and then selected the bits they needed. This code had the effect of bringing the entire database into memory at once!

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第46章《原书第06章|Repositories》(源文件:_epub-src/0321125215_ch06lev1sec3.html;小节 Client Code Ignores Repository Implementation; Developers Do Not) - 结论依据:原文转述 Kyle Brown 遇到的内存问题,原因是“all objects”查询实例化整个数据库;前段明确仓储可返回对象数或数值属性合计。 - 原始内容:The developers had done this using a query called "all objects," which instantiated each of the objects and then selected the bits they needed. This code had the effect of bringing the entire database into memory at once! ... Developers need to understand the implications of using encapsulated behavior.