Restored previous entity retrieval

Using temporary tables turned out to be more expensive on bigger databases.
Restoring two queries version.
This commit is contained in:
Marcin Kurczewski 2013-11-30 18:13:46 +01:00
parent e93c3588f9
commit 992b9ba5ac

View file

@ -72,38 +72,11 @@ abstract class AbstractModel extends RedBean_SimpleModel
public static function getEntitiesWithCount($query, $perPage = null, $page = 1)
{
$table = static::getTableName();
$tempTable = $table . '_temp';
R::begin();
R::exec('CREATE TEMPORARY TABLE ' . $tempTable . '(id INTEGER)');
R::exec('CREATE INDEX idx_fk_' . $tempTable . '_id ON ' . $tempTable . '(id)');
$dbQuery = R::$f->getNew()->begin();
$dbQuery->insertInto($tempTable . '(id)');
$dbQuery->select($table . '.id');
$builder = static::getQueryBuilder();
if ($builder)
$builder::build($dbQuery, $query);
else
$dbQuery->from($table);
$dbQuery->get();
$count = intval(R::getCell('SELECT COUNT(*) FROM ' . $tempTable));
$rows = R::$f->getNew()
->begin()
->select($table . '.*')
->from($tempTable)
->innerJoin($table)
->on($table . '.id = ' . $tempTable . '.id')
->limit('?')->put($perPage)
->offset('?')->put(($page - 1) * $perPage)
->get();
R::rollback();
$entities = self::convertRows($rows, $table, true);
return [$entities, $count];
return
[
self::getEntities($query, $perPage, $page, true),
self::getEntityCount($query)
];
}
public static function create()