我使用的应用程序从外部服务器检索数据(7k行CSV格式的字符串),以更新我自己的实体。每一行都是库存中的一项。
今天,这项工作做得很好,但非常非常慢:超过60秒(prod-env)来检索数据,将其推送到2D阵列中,更新BDD,最后加载一个显示BDD内容的页面。当只显示页面时,它大约是20秒(仍然是戳)。
这是探查器的时间线结果,同时只显示记录:Symfony的探查器时间线无论如何,我无法评测"updateAction",因为我没有出现在最后十个请求列表中。
2天前,我检查了CSV文件的每一行,只在需要时添加它,我软删除了项目,以便稍后在库存中恢复它,等等,但以这样的速度,我尝试了很多事情来获得正常的性能。一开始,所有的东西都在控制器中,我将添加/删除的功能移到了一个专用服务中,然后移到了存储库中,最终将其放回了我的控制器中。为了获得不错的结果,我尝试清空数据库,然后在不检查的情况下重新填充。首先,使用LOAD DATA LOCAL INFILE,但它与我的表模式不兼容(或者我理解错误),现在我只是在用CSV填充表之前清空表(没有任何控制)。我之前给出的时间分数是最后一次尝试(这是最好的一次)。但我们聊得够多了这是我的控制器:
public function majMatosClanAction()
{
$resMaj = $this->majClanCavernes();
if ($resMaj === NULL)
{
$this->get('session')->getFlashBag()->add('alert-danger', 'Unidentified');
return $this->redirect($this->generateUrl('loki_gbl'));
} else if ($resMaj === FALSE)
{
$this->get('session')->getFlashBag()->add('alert-warning','password update required');
return $this->redirect($this->generateUrl('loki_gbl_ST'));
} else
{
$this->get('session')->getFlashBag()->add('alert-success','success');
return $this->redirect($this->generateUrl('loki_gbl_voirMatosClan'));
}
}
这是我的控制器调用的函数:
public function majClanCavernes()
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$outils = $this->container->get('loki_gbl.outils');
if ($user !== NULL)
{
$pwd = $user->getGob()->getPwd();
$num = $user->getGob()->getNum();
if($outils->checkPwd($num, $pwd) !== TRUE) return FALSE;
$em = $this->getDoctrine()->getManager();
//This is a temporary solution
//////////////////////////////////////////////
$connection = $em->getConnection();
$platform = $connection->getDatabasePlatform();
$connection->executeUpdate($platform->getTruncateTableSQL('MatosClan', true ));
//////////////////////////////////////////////
$repository = $em->getRepository('LokiGblBundle:MatosClan');
$urlMatosClan = "http://ie.gobland.fr/IE_ClanCavernes.php?id=".$num."&passwd=".$pwd;
//encode and format the string via a service
$infosBrutes = $outils->fileGetInfosBrutes($urlMatosClan);
//$csv is a 2D array containing the datas
$csv = $outils->getDatasFromCsv($infosBrutes);
foreach($csv as $item)
{
$newItem = new MatosClan;
$newItem->setNum($item[0]);
$newItem->setType($item[1]);
[...]
$em->persist($newItem);
}
$em->flush();
return TRUE;
}
else{
return NULL;
}
}
怎么了?7k线路没有那么大!
可能是缺少硬件的问题吗?
点击此处查看条令的批处理文档。
您还可以禁用日志记录:
$em->getConnection()->getConfiguration()->setSQLLogger(null);