ZF2学说:何时刷新ObjectManager [英] ZF2 Doctrine: When to flush ObjectManager
问题描述
何时刷新实体/对象管理器的最佳时间"是什么? 是否应该在每次持久操作之后?还是应该在例如postDispatch?
when is the best "time" to flush the Entity/Object-manager? Should it be after every persist operation? Or should it be run once on e.g. postDispatch?
推荐答案
在每次持久化之后运行它实际上是一种反模式.理想情况下,您应该在请求结束时运行一次.
Running it after every persist is an antipattern actually. Ideally, you should run it once at the end of the request.
我不会将其放在postDispatch处理程序中,因为这意味着它将在每个请求之后运行,并且这在例如列表页面(其中您列出具有许多关系的实体)的性能上将是代价高昂的,因为Doctrine将不得不检查许多实体以进行更改.
I would not put it in a postDispatch handler, because that means it will run after every request, and that is going to be costly performance wise on, for example, list pages, where you list entities with many relations, because Doctrine will have to examine many entities for changes.
将其放在修改数据的操作结束时.
Put it at the end of actions that modify data.
这篇关于ZF2学说:何时刷新ObjectManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!