refactor count loop for having better performance has mentionned in #193
This commit is contained in:
@@ -337,7 +337,7 @@ abstract class BaseLoop
|
||||
* @param $pagination
|
||||
* @return LoopResult
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
public function exec(&$pagination, $count = false)
|
||||
{
|
||||
if ($this instanceof PropelSearchLoopInterface) {
|
||||
$searchModelCriteria = $this->buildModelCriteria();
|
||||
@@ -361,6 +361,10 @@ abstract class BaseLoop
|
||||
}
|
||||
}
|
||||
|
||||
if ($count) {
|
||||
return $results ? count($results) : 0;
|
||||
}
|
||||
|
||||
$loopResult = new LoopResult($results);
|
||||
|
||||
if (true === $this->countable) {
|
||||
|
||||
@@ -91,9 +91,7 @@ class TheliaLoop extends AbstractSmartyPlugin
|
||||
|
||||
$dummy = null;
|
||||
|
||||
$loopResults = $loop->exec($dummy);
|
||||
|
||||
return $loopResults->valid() ? $loopResults->getCount() : 0;
|
||||
return $loop->exec($dummy, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -367,18 +367,18 @@ try {
|
||||
//categories and products
|
||||
$productIdList = array();
|
||||
$categoryIdList = array();
|
||||
for ($i=1; $i<5; $i++) {
|
||||
for ($i=1; $i<20; $i++) {
|
||||
$category = createCategory($faker, 0, $i, $categoryIdList, $contentIdList);
|
||||
|
||||
for ($j=1; $j<rand(0, 5); $j++) {
|
||||
for ($j=1; $j<rand(0, 20); $j++) {
|
||||
$subcategory = createCategory($faker, $category->getId(), $j, $categoryIdList, $contentIdList);
|
||||
|
||||
for ($k=0; $k<rand(0, 5); $k++) {
|
||||
for ($k=0; $k<rand(0, 20); $k++) {
|
||||
createProduct($faker, $subcategory, $k, $template, $productIdList);
|
||||
}
|
||||
}
|
||||
|
||||
for ($k=1; $k<rand(1, 6); $k++) {
|
||||
for ($k=1; $k<rand(1, 50); $k++) {
|
||||
createProduct($faker, $category, $k, $template, $productIdList);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user