在我的symfony应用程序中,我正在生成一个表单以便参数化某些成分。 我现在面临的情况是用户开始管理成千上万的成分。
只有200种成分,php内存使用量超过最大120Mo。
以下显示使用50Mo的动作统计数据和仅创建表单的动作统计数据需要40Mo。如果我尝试渲染视图,它会崩溃。
我可以做些什么来避免形式占用这么多记忆?
我的控制器操作:
/**
* @Route("/set_ingredient_stock", name="set_ingredient_stock")
* @Method({"PUT","GET"})
* @Template(":FoodAnalytics/UserIngredient:set_ingredient_stock.html.twig")
* @param Request $request
* @Security("is_granted('organizer')")
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
*/
public function setIngredientStockAction(Request $request)
{
r('init : ' . ceil(memory_get_usage() / 1000000));
$userIngredientManager = $this->get('user_ingredient_manager');
r('manager : ' . ceil(memory_get_usage() / 1000000));
/** @var User $user */
$user = $this->getDoctrine()->getRepository('AppBundle:User\User')->findUserWithUserIngredients($this->getPortfolioUser());
r('user : ' . ceil(memory_get_usage() / 1000000));
$setStockIngredientForm = $userIngredientManager->getSetIngredientStockForm($user);
r('form : ' . ceil(memory_get_usage() / 1000000));
if ($request->getMethod()=='PUT')
{
$formManager = $this->get('form_manager');
if ($formManager->handleRequestAndFlush($setStockIngredientForm, $user))
{
$this->addSuccess("Le stock d'ingrédients à été mis à jour");
return $this->redirectToRoute('set_ingredient_stock');
}
$this->addInvalidFormMessage();
}
$nonExecutedTasks = $this->getDoctrine()->getRepository('AppBundle:FoodAnalytics\Task')->getNonExecutedTasksQueryBuilder($this->getPortfolioUser())->select('COUNT(t)')->getQuery()->getSingleScalarResult();
$nonReceivedOrders = $this->getDoctrine()->getRepository('AppBundle:MarketPlace\Order')->getNonReceivedOrdersQueryBuilder($this->getPortfolioUser())->select('COUNT(o)')->getQuery()->getSingleScalarResult();;
$horizon = $user->getParameter(User::STOCK_HORIZON) ?: 7;
r('small_variables : ' . ceil(memory_get_usage() / 1000000));
$userIngredients = $this->getDoctrine()->getRepository('AppBundle:FoodAnalytics\UserIngredient')->getUserIngredientsWithJoinsIndexedByProductIds($this->getPortfolioUser());
r('user_ingredients : ' . ceil(memory_get_usage() / 1000000));
$stocks = $userIngredientManager->getUserIngredientStocks($userIngredients, $horizon);
~r('stocks : ' . ceil(memory_get_usage() / 1000000));
return array(
'set_stock_ingredient_form' => $setStockIngredientForm->createView(),
'non_executed_tasks' => $nonExecutedTasks,
'non_received_orders' => $nonReceivedOrders,
'stocks' => $stocks,
'horizon' => $horizon
);
}
转储:
init : 50
manager : 51
user : 61
form : 100
small_variables : 100
user_ingredients : 101
stocks : 105
编辑: 生成表单的方法刚刚创建了一个常规的symfony表单,该表单附加到拥有另一个类型生成的userIngredients集合的用户。每个用户成分有3个字段。