Symfony2查询应该针对相同的实体字段进行优化


Symfony2 queries should be optimized for same entity fields

我有三个实体:RecipeRecipeIngredientIngredient。每个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