Merge branch 'optim'
This commit is contained in:
@@ -67,6 +67,9 @@ abstract class BaseLoop
|
|||||||
protected $timestampable = false;
|
protected $timestampable = false;
|
||||||
protected $versionable = false;
|
protected $versionable = false;
|
||||||
|
|
||||||
|
private static $cacheLoopResult = array();
|
||||||
|
private static $cacheCount = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Loop
|
* Create a new Loop
|
||||||
*
|
*
|
||||||
@@ -334,6 +337,9 @@ abstract class BaseLoop
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function count()
|
public function count()
|
||||||
|
{
|
||||||
|
$hash = $this->args->getHash();
|
||||||
|
if(false === array_key_exists($hash, self::$cacheCount))
|
||||||
{
|
{
|
||||||
$count = 0;
|
$count = 0;
|
||||||
if ($this instanceof PropelSearchLoopInterface) {
|
if ($this instanceof PropelSearchLoopInterface) {
|
||||||
@@ -351,15 +357,20 @@ abstract class BaseLoop
|
|||||||
$count = count($searchArray);
|
$count = count($searchArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self::$cacheCount[$hash] = $count;
|
||||||
|
}
|
||||||
|
|
||||||
return $count;
|
return self::$cacheCount[$hash];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $pagination
|
* @param $pagination
|
||||||
* @return LoopResult
|
* @return LoopResult
|
||||||
*/
|
*/
|
||||||
public function exec(&$pagination, $count = false)
|
public function exec(&$pagination)
|
||||||
|
{
|
||||||
|
$hash = $this->args->getHash();
|
||||||
|
if(false === array_key_exists($hash, self::$cacheLoopResult))
|
||||||
{
|
{
|
||||||
if ($this instanceof PropelSearchLoopInterface) {
|
if ($this instanceof PropelSearchLoopInterface) {
|
||||||
$searchModelCriteria = $this->buildModelCriteria();
|
$searchModelCriteria = $this->buildModelCriteria();
|
||||||
@@ -383,10 +394,6 @@ abstract class BaseLoop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($count) {
|
|
||||||
return $results ? count($results) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$loopResult = new LoopResult($results);
|
$loopResult = new LoopResult($results);
|
||||||
|
|
||||||
if (true === $this->countable) {
|
if (true === $this->countable) {
|
||||||
@@ -399,7 +406,11 @@ abstract class BaseLoop
|
|||||||
$loopResult->setVersioned();
|
$loopResult->setVersioned();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->parseResults($loopResult);
|
self::$cacheLoopResult[$hash] = $this->parseResults($loopResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$cacheLoopResult[$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