Commit f03c62e321ddf0787129a45370a39ea2e3452b40

Authored by Benjamin Renard
1 parent 1457bf10

Keep in cache result of expression parser

Showing 1 changed file with 13 additions and 5 deletions   Show diff stats
src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php
... ... @@ -11,6 +11,8 @@ class IHMParamManagerClass
11 11 protected $templateParamsManager = null;
12 12 protected $paramImpexMgr = null;
13 13 protected $ttCatMgr = null;
  14 +
  15 + protected $cacheExpressionParser = null;
14 16  
15 17 /*
16 18 * @brief Constructor
... ... @@ -18,6 +20,7 @@ class IHMParamManagerClass
18 20 function __construct()
19 21 {
20 22 $this->templateParamsManager = new IHMParamTemplateClass();
  23 + $this->cacheExpressionParser = array();
21 24 }
22 25  
23 26 public function addGeneratedParam($paramId, $expression, $sampling, $paramsData)
... ... @@ -276,12 +279,13 @@ class IHMParamManagerClass
276 279 */
277 280 private function addDerivedParam($param,$paramsData)
278 281 {
  282 + $time = time();
279 283 if (!isset($this->userParameterLoader))
280 284 $this->userParameterLoader = new IHMUserParamLoaderClass();
281 285  
282 286 //get derived parameter info
283 287 $res = $this->userParameterLoader->getDerivedParameterFromName($param);
284   -
  288 +
285 289 if (!$res["success"])
286 290 throw new Exception('Error to load derived parameter file : '.$res["message"]);
287 291  
... ... @@ -299,7 +303,7 @@ class IHMParamManagerClass
299 303 $expressionInfo['params'], $res["param"]["timestep"],
300 304 0,$res["param"]["dateModif"],!empty($res["param"]["info"]["units"]) ? $res["param"]["info"]["units"] : "",
301 305 !empty($res["param"]["info"]["yTitle"]) ? $res["param"]["info"]["yTitle"] : "", $paramsData);
302   -
  306 +
303 307 return array("id" => $paramId, "indexes" => array(), "calib_infos" => array());
304 308 }
305 309  
... ... @@ -675,6 +679,10 @@ class IHMParamManagerClass
675 679 }
676 680  
677 681 public function parseExpression($expression, $workingDir) {
  682 + $outputFileName = "parser_".md5($expression).".xml";
  683 + if (array_key_exists($outputFileName, $this->cacheExpressionParser)) {
  684 + return $this->cacheExpressionParser[$outputFileName];
  685 + }
678 686 $parserData = new ParserRequestDataClass();
679 687 $parserData->setManagerFilePath(IHMConfigClass::getProcessManagerFilePath());
680 688 $parserData->addExpression($expression);
... ... @@ -683,8 +691,7 @@ class IHMParamManagerClass
683 691 $parserData->setConstantsFilePath(IHMConfigClass::getConstantsFilePath());
684 692 $parserData->setFunctionsFilePath(IHMConfigClass::getFunctionsFilePath());
685 693 $parserData->setParamTemplatesFilePath(IHMConfigClass::getParamTemplateListFilePath());
686   - $outputFileName = "parser_".md5($expression).".xml";
687   - $parserData->setOutputFileName("parser_".md5($expression).".xml");
  694 + $parserData->setOutputFileName($outputFileName);
688 695 $resultFilePath = $workingDir."/".$outputFileName;
689 696  
690 697 $parserRequest = new ParserRequestClass();
... ... @@ -776,6 +783,7 @@ class IHMParamManagerClass
776 783 }
777 784 }
778 785  
779   - return array('success' => TRUE, 'expression' => $kernelExpression, 'params' => $params);
  786 + $this->cacheExpressionParser[$outputFileName] = array('success' => TRUE, 'expression' => $kernelExpression, 'params' => $params);
  787 + return $this->cacheExpressionParser[$outputFileName];
780 788 }
781 789 }
... ...