我有三个实体:Recipe
、RecipeIngredient
和Ingredient
。每个Recipe
都有许多RecipeIngredients
。每个RecipeIngredient
都有一个Ingredient
。我的食谱管理员包括一个用于编辑RecipeIngredients
的收藏字段。集合字段包含多个表单,每个表单对应一个RecipeIngredient
。此窗体包含用于选择Ingredient
的实体字段。问题是,当我在表单上有80个RecipeIngredients
时,Symfony会进行80个相同的查询,每个字段一个。
这些查询基本上如下所示:
SELECT (all the fields) FROM recipe_ingredients ORDER BY name
重要的是一切都是一样的。我认为这不正常,如何优化以只需要一个查询?
我认为
您可以尝试使用ResultCache驱动程序。
doctrine:
orm:
..
..
result_cache_driver:
type: memcache
host: localhost
port: 11211
instance_class: Memcache