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 $timestampable = false;
|
||||||
protected $versionable = false;
|
protected $versionable = false;
|
||||||
|
|
||||||
|
private static $cache = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Loop
|
* Create a new Loop
|
||||||
*
|
*
|
||||||
@@ -360,6 +362,9 @@ abstract class BaseLoop
|
|||||||
* @return LoopResult
|
* @return LoopResult
|
||||||
*/
|
*/
|
||||||
public function exec(&$pagination, $count = false)
|
public function exec(&$pagination, $count = false)
|
||||||
|
{
|
||||||
|
$hash = $this->args->getHash();
|
||||||
|
if(false === array_key_exists($hash, self::$cache))
|
||||||
{
|
{
|
||||||
if ($this instanceof PropelSearchLoopInterface) {
|
if ($this instanceof PropelSearchLoopInterface) {
|
||||||
$searchModelCriteria = $this->buildModelCriteria();
|
$searchModelCriteria = $this->buildModelCriteria();
|
||||||
@@ -399,7 +404,11 @@ abstract class BaseLoop
|
|||||||
$loopResult->setVersioned();
|
$loopResult->setVersioned();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->parseResults($loopResult);
|
self::$cache[$hash] = $this->parseResults($loopResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$cache[$hash];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkInterface()
|
protected function checkInterface()
|
||||||
|
|||||||
@@ -144,4 +144,15 @@ class ArgumentCollection implements \Iterator
|
|||||||
{
|
{
|
||||||
reset($this->arguments);
|
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