Optimalization: faster but dirty row retrieval
This commit is contained in:
parent
518311ff61
commit
1e954bb815
2 changed files with 17 additions and 1 deletions
|
@ -106,7 +106,7 @@ class PostController
|
|||
$postCount = Model_Post::getEntityCount($query);
|
||||
$pageCount = ceil($postCount / $postsPerPage);
|
||||
$page = max(1, min($pageCount, $page));
|
||||
$posts = Model_Post::getEntities($query, $postsPerPage, $page);
|
||||
$posts = Model_Post::getEntitiesFast($query, $postsPerPage, $page);
|
||||
|
||||
$this->context->transport->paginator = new StdClass;
|
||||
$this->context->transport->paginator->page = $page;
|
||||
|
|
|
@ -26,6 +26,7 @@ abstract class AbstractModel extends RedBean_SimpleModel
|
|||
$dbQuery->limit('?')->put($perPage);
|
||||
$dbQuery->offset('?')->put(($page - 1) * $perPage);
|
||||
}
|
||||
|
||||
$rows = $dbQuery->get();
|
||||
return $rows;
|
||||
}
|
||||
|
@ -38,6 +39,21 @@ abstract class AbstractModel extends RedBean_SimpleModel
|
|||
return $entities;
|
||||
}
|
||||
|
||||
public static function getEntitiesFast($query, $perPage = null, $page = 1)
|
||||
{
|
||||
$table = static::getTableName();
|
||||
$rows = self::getEntitiesRows($query, $perPage, $page);
|
||||
$entities = R::dispense($table, count($rows));
|
||||
reset($entities);
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$entity = current($entities);
|
||||
$entity->import($row);
|
||||
next($entities);
|
||||
}
|
||||
return $entities;
|
||||
}
|
||||
|
||||
public static function getEntityCount($query)
|
||||
{
|
||||
$table = static::getTableName();
|
||||
|
|
Loading…
Reference in a new issue