cache ParseResult for not calculating twice the same loop
This commit is contained in:
@@ -67,6 +67,8 @@ abstract class BaseLoop
|
||||
protected $timestampable = false;
|
||||
protected $versionable = false;
|
||||
|
||||
private static $cache = array();
|
||||
|
||||
/**
|
||||
* Create a new Loop
|
||||
*
|
||||
@@ -360,6 +362,9 @@ abstract class BaseLoop
|
||||
* @return LoopResult
|
||||
*/
|
||||
public function exec(&$pagination, $count = false)
|
||||
{
|
||||
$hash = $this->args->getHash();
|
||||
if(false === array_key_exists($hash, self::$cache))
|
||||
{
|
||||
if ($this instanceof PropelSearchLoopInterface) {
|
||||
$searchModelCriteria = $this->buildModelCriteria();
|
||||
@@ -399,7 +404,11 @@ abstract class BaseLoop
|
||||
$loopResult->setVersioned();
|
||||
}
|
||||
|
||||
return $this->parseResults($loopResult);
|
||||
self::$cache[$hash] = $this->parseResults($loopResult);
|
||||
}
|
||||
|
||||
return self::$cache[$hash];
|
||||
|
||||
}
|
||||
|
||||
protected function checkInterface()
|
||||
|
||||
@@ -144,4 +144,15 @@ class ArgumentCollection implements \Iterator
|
||||
{
|
||||
reset($this->arguments);
|
||||
}
|
||||
|
||||
public function getHash()
|
||||
{
|
||||
$arguments = $this->arguments;
|
||||
|
||||
if (array_key_exists('name', $arguments)) {
|
||||
unset($arguments['name']);
|
||||
}
|
||||
|
||||
return sha1(serialize($arguments));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user